Solved

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

Posted on 2006-07-09
8
29,108 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

696 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