Strange behavior of DateList when converting string

4

1

DateList experiences some strange behavior which i cannot explain. This code works fine:

DateList[{"2012September1211:45:26", {"Year", "MonthName", "Day", 
   "Hour", ":", "Minute", ":", "Second"}}]

Returning

{2012, 9, 12, 11, 45, 26.}

But this code doesn't work:

DateList[{"2012October1211:45:26", {"Year", "MonthName", "Day", 
   "Hour", ":", "Minute", ":", "Second"}}]

Returning this error message:

DateString::str: String 2012October1211:45:26 cannot be interpreted as a date in format {Year,MonthName,Day,Hour,:,Minute,:,Second}. >>

The only thing i changed is the month from september to october.

Really frustrating, i'm already staring at it for 2 hours...

Question: What am i doing wrong?

Aart Goossens

Posted 2012-11-17T16:13:18.740

Reputation: 1 570

The October version works on my end. What version of Mathematica are you on? – J. M.'s ennui – 2012-11-17T16:19:19.797

Both lines also work on version 7. – Mr.Wizard – 2012-11-17T16:22:34.150

Works here too. – rm -rf – 2012-11-17T16:44:16.477

5I had lots of problems with date parsing functions that others couldn't reproduce. It turns out how these work depends on the regional settings of your system! You'll only get the documented behaviour on Windows with a US English locale. – Szabolcs – 2012-11-17T16:54:31.420

(With non English locals it doesn't simply use the month names I another language. Often parsing is just broken :( ) – Szabolcs – 2012-11-17T16:57:01.290

To confirm what Szabolcs said I ran this in bash: expr='DateList[{"2012October1211:45:26", {"Year", "MonthName", "Day","Hour", ":", "Minute", ":", "Second"}}]'; math <<< $expr; export LANG='zu_ZA'; math <<< $expr; – ssch – 2012-11-17T17:08:51.253

I retagged it as bugs and version-8 – ssch – 2012-11-17T17:20:37.450

I'm running mma version 8.0.4.0 at Ubuntu 64-bit – Aart Goossens – 2012-11-17T21:24:40.453

Answers

3

Solution credit to Szabolcs comment!

If you are on linux you can fix this by starting mathematica from your terminal as:

export LANG=en_US.UTF-8; mathematica

Or if it is not in your path:

export LANG=en_US.UTF-8; /Directory/To/Mathematica/Version/Executables/Mathematica

ssch

Posted 2012-11-17T16:13:18.740

Reputation: 16 150

It works! I'm glad it wasn't some simple typo i made... – Aart Goossens – 2012-11-17T21:27:31.753

Is it in some way not wise to start mma alway with this command? – Aart Goossens – 2012-11-17T21:28:24.233