Hi,
I have a property in a class with datatype Datetime?
for ex:
int Datetime? test;
Now i want to convert this test to "mm/dd/yyyy" format
I tried with .Tostring("mm/dd/yyyy") its not working.
it says an error
No overload for method ''Tostring" takes 1 argument.
Do anyone faced this problem before???
Thanks,
Prasant
Loading

VulpesPosted Aug 16, 2012, 10:22 AM
string s = (test != null) ? ((DateTime)test).ToString("MM/dd/yyyy") : "";
or you can use the HasValue and Value properties:
string s = test.HasValue ? test.Value.ToString("MM/dd/yyyy") : "";
Sukesh MarlaPosted Aug 16, 2012, 12:56 PM
Check this is correct answer if it really helped.
Santhosh Kumar JayaramanPosted Aug 16, 2012, 10:57 AM
The actual datetime value is present inside test.Value..
So instead of trying test.Tostring("mm/dd/yyyy")
try test.Value.Tostring("mm/dd/yyyy")