i have a string like this:
1/1/2011
i need to convert it to DateTime
i have so far tried with no luck:
DateTime.ParseExact("1/1/2011"
, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture)
what am i doing wrong?
i have a string like this:
1/1/2011
i need to convert it to DateTime
i have so far tried with no luck:
DateTime.ParseExact("1/1/2011"
, "M/d/yyyy", System.Globalization.CultureInfo.InvariantCulture)
what am i doing wrong?
That code should work absolutely fine, and does for me:
using System;
using System.Globalization;
class Test
{
static void Main()
{
DateTime dt = DateTime.ParseExact("1/1/2011",
"M/d/yyyy",
CultureInfo.InvariantCulture);
Console.WriteLine(dt);
}
}
You say you've tried "with no luck" - what happens for you? Can you come up with a similar short but complete program that fails?
Use DateTime.Parse (or better, DateTime.TryParse) instead of ParseExact.