• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 29235
  • Last Modified:

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.
0
r_pat72
Asked:
r_pat72
  • 2
  • 2
1 Solution
 
bruintjeCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now