5

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,774
  • 4
  • 24
  • 48

1 Answers1

19

try this one,

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