Solved

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

Posted on 2006-07-09
8
29,071 Views
Last Modified: 2010-10-05
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
Comment
Question by:r_pat72
  • 2
  • 2
8 Comments
 
LVL 44

Accepted Solution

by:
bruintje earned 500 total points
ID: 17070694
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
 
LVL 22

Expert Comment

by:cookre
ID: 17070697
DateTimeVar.Date.ToString("yyyy-MM-dd")
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17070707
string time=TimeYouWantToConvert.ToString("yyyy-MM-dd");
cheers
0
 
LVL 5

Expert Comment

by:t_itanium
ID: 17070710
sorry all you wrote while i was doing so

:)
0
 
LVL 22

Expert Comment

by:cookre
ID: 17072246
It happens all the time.

Whoa, me too!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now