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
.
try this one,
string strdatetime = datetime.HasValue ? datetime.Value.ToString("MM/dd/yyyy") : string.Empty;
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