Convert string to datetime Using C#
Posted by Tihomir Ivanov on 02 January 2010 13:37
Rating: 0.00
Sometimes you may have strings to represent dates (ex. 20100102 that represents 2010 January 2), here's an example how it can be converted to DateTime:
string dtString = "20100102";
IFormatProvider culture = new CultureInfo("en-EN", false);
DateTime dt = DateTime.ParseExact(dtString, "yyyyMMdd", culture, DateTimeStyles.NoCurrentDateDefault);
Now, if you want to convert DateTime variable to string in the format above, here's an example how it can be done:
String dtNewString = String.Format("{0:dd/MM/yyyy}", dt);
Comments:
No comments yet.