How can I format a nullable DateTime with ToString()?

Posted by Edward Tanguay on Stack Overflow See other posts from Stack Overflow or by Edward Tanguay
Published on 2009-12-02T13:57:33Z Indexed on 2010/05/26 18:51 UTC
Read the original article Hit count: 270

Filed under:
|
|
|

How can I convert the nullable DateTime dt2 to a formatted string?

DateTime dt = DateTime.Now;
Console.WriteLine(dt.ToString("yyyy-MM-dd hh:mm:ss")); //works

DateTime? dt2 = DateTime.Now;
Console.WriteLine(dt2.ToString("yyyy-MM-dd hh:mm:ss")); //gives following error:

no overload to method ToString takes one argument

© Stack Overflow or respective owner

Related posts about c#

Related posts about datetime