Converting datetime value to yyyy-mm-dd format in c#

I am using a variable in my code which is a datetime.
I need to convert this to a format which is "yyyy-mm-dd".

How could i do this in c#.

Here is my code

private DateTime DateofBirth
 DateofBirth = mm/dd/yyyy 12:00 AM

I need to convert this to YYYY-MM-DD.

Pls help.
r_pat72Asked:
Who is Participating?
 
bruintjeConnect With a Mentor Commented:
Hi r_pat72,
----------

you could try something like
DateofBirth.ToString("yyyy-MM-dd")

in my test i used a string to start from

string o = "05/13/99 12:00AM";
DateTime DateofBirth;
DateTime.TryParse(o, out DateofBirth);
MessageBox.Show(DateofBirth.ToString("yyyy-MM-dd"));

----------
bruintje
share what you know, learn what you don't
0
 
cookreCommented:
DateTimeVar.Date.ToString("yyyy-MM-dd")
0
 
t_itaniumCommented:
string time=TimeYouWantToConvert.ToString("yyyy-MM-dd");
cheers
0
 
t_itaniumCommented:
sorry all you wrote while i was doing so

:)
0
 
cookreCommented:
It happens all the time.

Whoa, me too!
0
All Courses

From novice to tech pro — start learning today.