DateTime.Parse

Reapz

Regular
Joined
Dec 15, 2002
Messages
74
I'm using DateTime.Parse to convert 2 strings into DateTimes to find the time between the two.

Now if the string was in the format dd/mm/yyyy hh:mm:ss my code would work perfectly because im in the UK. However, the string is always mm/dd/yyyy hh:mm:ss so Parse always throws a fit when it gets there or if the dd is 12 or less returns the wrong date.

How do I get my app to think its in the US just for that one line of code so it will recognise something like say 10/31/2003 as a valid date?

Cheers.
 
Well like I always say... If you stare blankly at the screen for long enuff the answer will jump out and slap you upside the head.

Incase it useful to anyone else...

Use DateTime.ParseExact instead. That way you get to specify what format the string you are reading is in without have to mess about with regional settings.

In my case...

Visual Basic:
TimeEntered = DateTime.ParseExact(Joined, "MM/dd/yyyy HH:mm:ss", System.Globalization.DateTimeFormatInfo.CurrentInfo)
 
Back
Top