Possible duplicate:How to format a null DateTime using ToString ()?
appeared parsing DateTime? in a specific format. How:
DateTime t1 = ...; string st1 = t1.ToString(format); //<-- works DateTime? t1 = ...; string st1 = t1.ToString(format); //Dont work.
No overload method for DateTime?
if (t1.HasValue) string st1 = t1.Value.ToString(format);
Use Coalesce statement
DateTime? t1 = ...; string st1 = t1 ?? t1.Value.ToString(format);
you can try it like this: nullabale type has hasValue property Nullable has value
if (t1.HasValue) t1.Value.ToString(yourFormat)
First you need to check if DateTime is null or not.
string strDate = (st1 != null ? st1.Value.ToString(format) : "n/a");