Click to See Complete Forum and Search --> : DateTime.ParseExact


meenus
January 25th, 2010, 05:02 AM
Hi,
I want to parse data in string to a particular datetime format so that i am trying to use
DateTime.ParseExact ..

DateTime dateTime ;
DateTime.TryParseExact("10/20/2009", "dd/MM/yyyy", CultureInfo.InvariantCulture,DateTimeStyles.None, out dateTime);

But i have got the following error
" The DateTime represented by the string is not supported in calendar System.Globalization.GregorianCalendar"

pls give a solution to parse the date..

nelo
January 25th, 2010, 05:16 AM
Hi,
DateTime dateTime ;
DateTime.TryParseExact("10/20/2009", "dd/MM/yyyy", CultureInfo.InvariantCulture,DateTimeStyles.None, out dateTime);

I think the problem is that you're specifying "20" as the value for "MM" or the month. The Gregorian Calendar only has 12 months. Try switching those values around e.g. "20/10/2009" or "MM/dd/yyyy"