I’m trying to parse a date/time string using DateTime.ParseExact. It works everywhere, except on one machine – it just will not parse on that machine. The question is: Why? What could be different on that machine so that it will cause this behaviour?
Here are some things that I’ve already looked at:
- The
CultureInfois passed toDateTime.ParseExact, namelyCultureInfo.InvariantCulture - The regional settings on the rogue machine is the same as the settings on a machine where the parsing works.
- Yes, the string is in the correct format, which is
dd/MM/yyyy HH:mm:ss
I always find that regional settings can be tricky, and you can never assume that the users of your application will even have their machines setup correctly in the first place!
A catch-all that I’ve been using to parse dates in if they have to be strings is to parse it in the ‘dd/MMM/yyyy’ format, e.g. ’14/JAN/2009′ will translate nicely no matter what the settings are.
Incidentally this trick also works with SQL Server as well 🙂