I am trying to Parse a String date and time into a single .NET DateTime object. I have the following code:
string dtObjFormat = "dd MMM YYYY HH:mm";
string mydatetimemash = e.Date + " " + e.Time; // this becomes 25 May 2013 10:30
DateTime dt;
if (DateTime.TryParseExact(mydatetimemash, dtObjFormat, CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
{
Console.WriteLine(dt);
} else
{
dt = DateTime.Now;
Console.WriteLine(dt);
}
But the TryParseExact always returns false for me, meaning the Parse fails. What am I doing wrong?
DateTime.TryParseExact("25 May 2013 10:30", "dd MMM yyyy HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt)works fine, whereas the variant with"YYYY"doesn't work.