4

I want to convert Nullable DataTime to string.

DateTime datetime = DateTime.Now;
string strdatetime = datetime.ToString("MM/dd/yyyy");

Above coding working fine, non nullable DateTime.

DateTime? datetime = DateTime.Now;
string strdatetime = datetime.ToString("MM/dd/yyyy");

This one showing error No overload for method 'ToString' takes 1 arguments.

Jesuraja
  • 3,644
  • 4
  • 23
  • 46

1 Answers1

16

try this one,

 string strdatetime = datetime.HasValue ? datetime.Value.ToString("MM/dd/yyyy") : string.Empty;
KarthikManoharan
  • 775
  • 4
  • 12