Solved

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

Posted on 2006-07-09
8
29,097 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

Suggested Solutions

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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