1

Best way of converting date like "December 6, 2011" to pattern like "yyyy-MM-dd" ?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Bomberis123
  • 358
  • 2
  • 13

1 Answers1

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