Windows Develop Bookmark and Share   
 index > Windows Forms General > Convert a string to datetime
 

Convert a string to datetime

Hi, how would I convert a string containing the following to a datetime?

"26 Sep 2009 (Sat) 11:01:27"


Thanks
GraemeP  Monday, September 28, 2009 10:36 PM
You can do:

DateTime date = DateTime.ParseExact("26 Sep 2009 (Sat) 11:01:27", "dd MMM yyyy (ddd) HH:mm:ss", CultureInfo.InvariantCulture);

You may need "d" instead of "dd" (if it's "3 Sep ..." or "03 Sep"). Also, I'm assuming 24hr time since you don't have AM/PM.

Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.  Monday, September 28, 2009 11:03 PM
You can do:

DateTime date = DateTime.ParseExact("26 Sep 2009 (Sat) 11:01:27", "dd MMM yyyy (ddd) HH:mm:ss", CultureInfo.InvariantCulture);

You may need "d" instead of "dd" (if it's "3 Sep ..." or "03 Sep"). Also, I'm assuming 24hr time since you don't have AM/PM.

Reed Copsey, Jr. - http://reedcopsey.com
Reed Copsey, Jr.  Monday, September 28, 2009 11:03 PM
Thanks!
GraemeP  Tuesday, September 29, 2009 6:47 AM

You can use google to search for other answers

Custom Search

More Threads

• Graphics.DrawString
• How can I set up a foreach loop to read through the rows of a grid?
• Automaticly paste text to current textbox
• DataGridViewCellValidating event caused by user close click, FormClosing
• Can I make my Message Filter targetting one child form in my MDI form?
• Error Reporting
• German characters in textbox
• Print Button
• Create Date user control
• Basic interop doesn't work, please help