I have a method that takes a parameter of the type DateTime?
I need to convert what I receive to a string of the format - yyyy-mm-dd
What is the cleanest optimal way to achieve this?
I have a method that takes a parameter of the type DateTime?
I need to convert what I receive to a string of the format - yyyy-mm-dd
What is the cleanest optimal way to achieve this?
Assuming dateParameter
if of type DateTime
, just like you said:
dateParameter.ToString("yyyy-mm-dd");
EDIT:
Since you edited your post to nullable DateTime
, here's an edit:
dateParameter.Value.ToString("yyyy-mm-dd");
You can use DateTime.ToString ..below is the sample code :-
datePassed.ToString("yyyy-mm-dd");
And for nullable DateTime :-
datePassed.Value.ToString("yyyy-mm-dd");