Tuesday, July 03, 2007

Convert Date String to DateTime Object??

You could use the DateTime.ParseExact() method to convert the date string into a DateTime instance:

Format SAP DateTime String to dd-MMM-yyyy?
string sapDate = ...
DateTime date = DateTime.ParseExact(sapDate, "yyyyMMdd", new System.Globalization.DateTimeFormatInfo());
string myString = date.ToString("MM/dd/yyyy");

Afterwards, use DateTime.ToString() method to convert it back to a string in the format you need.

No comments: