Thursday, January 10, 2013

Converting a String into DateTime format in C#.NET


Recently i was trying to parse string date time value into DateTime format but i was getting the error "String was not recognized as a valid DateTime"

Following is the string format i was trying to convert.

"10/10/2010 12:00:00 A.M"

The issue is with "." character in "A.M". I removed the "." character and it was working.

DateTime result = DateTime.ParseExact("10/10/2010 12:00:00 a.m".Replace(".", ""), "dd/MM/yyyy hh:mm:ss tt", null);

No comments:
Write comments
Recommended Posts × +