DateTime?.ToString(format)
11,051
Solution 1
if (t1.HasValue)
string st1 = t1.Value.ToString(format);
Solution 2
Use Coalesce Operator
DateTime? t1 = ...;
string st1 = t1 ?? t1.Value.ToString(format);
Solution 3
you can try like this , nullabale type has the property called hasValue Nullable has Value
if (t1.HasValue)
t1.Value.ToString(yourFormat)
Comments
-
VoonArt almost 2 years
Possible Duplicate:
How can I format a nullable DateTime with ToString()?got issue parsing DateTime? to specific format. Like:
DateTime t1 = ...; string st1 = t1.ToString(format); //<-- works DateTime? t1 = ...; string st1 = t1.ToString(format); //Dont work.
Theres no overload method for DateTime?