Best way of converting date like "December 6, 2011" to pattern like "yyyy-MM-dd" ?
Asked
Active
Viewed 1,269 times
1
-
`DateTime.ParseExact("December 6, 2011", "MMMM d, yyyy", DateTimeFormatInfo.InvariantInfo).ToString("yyyy-MM-dd");` – Tim Schmelter Apr 16 '15 at 07:57
-
Also good example, thanks ;) – Bomberis123 Apr 16 '15 at 08:09
1 Answers
1
You can use MMMM d, yyyy
format with an english-based culture like InvariantCulture
;
string s = "December 6, 2011";
DateTime dt;
if(DateTime.TryParseExact(s, "MMMM d, yyyy", CultureInfo.InvariantCulture,
DateTimeStyles.None, out dt))
{
Console.WriteLine(dt.ToString("yyyy-MM-dd")); // 2011-12-06
}
"MMMM"
format specifier represents the full name of the month based on culture settings.

Soner Gönül
- 97,193
- 102
- 206
- 364