DateTime TryParseExact a string containing a 3 letter month

c#, datetime

Solution

from your comments:

- if you want to parse 3 Letter Month use `MMM`.

- if you want to parse 24-Hour format you should use `HH` instead of `hh`.

Try This:

DateTime.TryParseExact(value, "dd MMM yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out converted);

Problem

I am writing an extension method to parse a specific string which contains a date and a time into a `DateTime` object using the `DateTime.TryParseExact()` Method. An example of the format is as follows: ` "29 November 2013 20:04" ` The code I am using to parse it to a DateTime is: ``` public static DateTime MyToDateTime(this string value) { DateTime converted; DateTime.TryParseExact(value, "dd MMM yyyy hh:mm", CultureInfo.InvariantCulture, DateTimeStyles.AllowWhiteSpaces, out converted); return converted; } ``` The result is always `DateTime.Min` (i.e `0001-01-01 00:00:00.000`) I cant figure out what is wrong with my format string. Any help would be appreciated.

Original source