A beginner question about date format

  • Thread starter Thread starter Geri Reshef
  • Start date Start date
G

Geri Reshef

Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + .... Day.tostring() seems to be unelegant..
 
Hi,

You can use DateTime.ToString:
DateTime.Today.ToString( "yy/mm/dd" , DateTimeFormatInfo.InvariantInfo );

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + ..... Day.tostring() seems to be unelegant..
 
DateTime.Now.ToString("YYYYMMDD");
please refer to some book, if it give u error!
Supose I have a control Text1 with todays date (21/12/2004).
How can I show it in a "yyyymmdd" format?
Solution like Text1.Value.Year.tostring() + .....Month.tostring() + ..... Day.tostring() seems to be unelegant..
 
Hi Geri,

Here's something you could try:

string txtDate = "21/12/2004";

System.Globalization.CultureInfo culture =
new System.Globalization.CultureInfo("FR-fr");

string newDate = DateTime.Parse(txtDate, culture).ToString("yyyyMMdd");

Console.WriteLine(newDate);

The code above demonstrates my suggestion of parsing your text value into a DateTime and reformatting it how you want. I'm making the assumption that you need to specify CultureInfo based on the way you formatted the date. It doesn't parse (raises an exception) on my machine, which is set to en-US.

Joe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Excel date format YYYYMMDD 1
To split, or to regex 4
Text to date format? 0
update problem 1
calendar 1
Error converting dd/MM/yyyy to sql server format 3
Check if a date exists in a record 1
Check Date Format 1

Back
Top