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?
The T is just a literal to separate the date from the time, and the Z means “zero hour offset” also known as “Zulu time” (UTC).
The string format should be: YYYY-MM-DDTHH:mm:ss. sssZ , where: YYYY-MM-DD – is the date: year-month-day. The character "T" is used as the delimiter.
Convert DateTime to String using the ToString() Method Use the DateTime. ToString() method to convert the date object to string with the local culture format. The value of the DateTime object is formatted using the pattern defined by the DateTimeFormatInfo.
if (t1.HasValue)
string st1 = t1.Value.ToString(format);
Use Coalesce Operator
DateTime? t1 = ...;
string st1 = t1 ?? t1.Value.ToString(format);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With