how to convert datetime

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
 
T

Tome

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
 

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

Top