Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Based on an example from here I try to parse dates from a table including the time, but it fails. This is the modified example:

Export["test.dat", {{"2010-05-19 22:23:43", 17}, {"2010-05-20 22:23:43", 20}, {"2010-05-21 22:23:43", 19}}, "FieldSeparators" -> " "];

Import["test.dat", "Table", "DateStringFormat" -> {"Year", "-", "Month", "-", "Day", " ", "Hour", ":", "Minute", ":", "Second"}]

Does anyone understand why it doesn't work in analogy to the other case?

thanks

share|improve this question
    
"DateStringFormat" seems to only return three elements (Y,M,D ) even if (Y,M,D H:M:S) are specified and apparently recognised. –  image_doctor Jul 6 '12 at 8:42

1 Answer 1

A workaround:

imported = Import["test.dat", "Table"]

We get:

(* {{"2010-05-19 22:23:43", 17}, {"2010-05-20 22:23:43", 
    20}, {"2010-05-21 22:23:43", 19}} *)

You can then apply DateList to convert it to a date list:

MapAt[DateList, #, 1] & /@ imported

(* {{{2010, 5, 19, 22, 23, 43.}, 17}, {{2010, 5, 20, 22, 23, 43.}, 
    20}, {{2010, 5, 21, 22, 23, 43.}, 19}} *)
share|improve this answer
1  
Even shorter: MapAt[DateList, #, 1] & /@ imported –  Mr.Wizard Jul 6 '12 at 10:21
    
@Mr.Wizard you're right, I'm going to correct it. –  VLC Jul 6 '12 at 10:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.