how to convert datetime

  • Thread starter Thread starter ziggislaw
  • Start date Start date
Z

ziggislaw

hello

how can I convert DateTime from "25.12.2005" to "2005-12-25
00:00:00.000" ?
Now I have DateTime as string (I get it from <asp:label>).

Thanks
 
To get it into your format you would use ToString() with formatting:
ToString("yyyy-MM-dd HH:mm:ss.fff")

There may be a better way to get the string into a DateTime, but this will do what you requested:

string date = "25.12.2005";

DateTime dt = new DateTime(Convert.ToInt32(date.Substring(6, 4)), Convert.ToInt32(date.Substring(3,
2)), Convert.ToInt32(date.Substring(0, 2)));

MessageBox.Show(dt.ToString("yyyy-MM-dd HH:mm:ss.fff"));

---Tome
http://www.pcdotcom.com
 
Back
Top