-3

I want to convert this string "12092014" into DateTime object as 12 september 2014.

Imran Ali
  • 87
  • 3
  • 11

1 Answers1

1

If ddMMyyyy is a standard date and time format of your CurrentCulture, you can use DateTime.Parse directly;

var date = DateTime.Parse("12092014");

If it is not, you can use custom date and time format with DateTime.TryParseExact method like;

string s = "12092014";
DateTime dt;
if(DateTime.TryParseExact(s, "ddMMyyyy",
                          CultureInfo.InvariantCulture,
                          DateTimeStyles.None, out dt))
{
    Console.WriteLine(dt);
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364