I have one date in string "18/07/2013 04:25:28 PM".How to convert this string to DateTime in c#.When I am trying to convert it into Date time I am getting an error "Input String is not in correct Date format"
4 Answers
DateTime.ParseExact(
"4/4/2010 4:20:00 PM",
"M/d/yyyy h:mm:ss tt",
CultureInfo.InvariantCulture);
2 Comments
Kamil Budziewski
He can parse with PM using
ParseExactMartijn van Put
I've changed the example. You must give the tt format with it.
You can try something like using DateTime.ParseExact using Custom Date and Time Format Strings
DateTime dt = DateTime.ParseExact("18/07/2013 04:25:28 PM", "dd/MM/yyyy hh:mm:ss tt", null);
Comments
I propose you the following solution :
DateTime d = DateTime.ParseExact("18/07/2013 04:25:28 PM",
"dd/MM/yyyy h:mm:ss tt",
CultureInfo.InvariantCulture);
To found the format string, I used Custom Date and Time Format Strings in MSDN
ParseExactorTryParseExactDateTime?