I try to parse DateTime.TryParse("30-05-2010"), and it throws an exception because it accepts MMddyyyy, and I need ddMMyyyy format. how can I change TryParse format?
thanks,
Dani
I try to parse DateTime.TryParse("30-05-2010"), and it throws an exception because it accepts MMddyyyy, and I need ddMMyyyy format. how can I change TryParse format?
thanks,
Dani
You can use the DateTime.TryParseExact method instead which allows you to specify the exact format the string is in
maybe you can use the overload with the formatprovider.
DateTime.TryParse("30-05-2010", <IFormatProvider>)
not sure how to correctly implement it, cant test anything here, but here's more info about the iformatprovider: http://msdn.microsoft.com/en-us/library/system.iformatprovider.aspx
If you're making that adjustment because of local usage, try this:
bool success = DateTime.TryParse("30-05-2010", out dt);
Console.Write(success); // false
// use French rules...
success = DateTime.TryParse("30-05-2010", new CultureInfo("fr-FR"),
System.Globalization.DateTimeStyles.AssumeLocal, out dt);
Console.Write(success); // true