0
$\begingroup$

Im wondering how can I formulate a function which receives input in the string format "day.month.year hours: minutes: seconds" (for example, "10.12.2012 3:25:05") and returns the time in the form of {year, month, day, hour, min, sec}.

I guess a start is

 datelist[{"10.12.2012 03:25:05", {"Day", "Month", "Year", "Hour", "Minute", "Second"}}]

but how do I continue?

$\endgroup$
  • 6
    $\begingroup$ Like this DateList[{"10.12.2012 03:25:05", {"Day", ".", "Month", ".", "Year", " ", "Hour", ":", "Minute", ":", "Second"}}] ? $\endgroup$ – b.gates.you.know.what Dec 10 '12 at 14:09
1
$\begingroup$

I'm not sure I understand your problem. Apart from the incorrect capitalization of the function name your suggested input

DateList[{"10.12.2012 03:25:05", {"Day", "Month", "Year", "Hour", "Minute", "Second"}}]

{2012, 12, 10, 3, 25, 5.}

seems to do exactly what you want.

Rolling that into a function is rather trivial:

ClearAll[dateConvert]
dateConvert[date_String] := 
        DateList[{date, {"Day", "Month", "Year", "Hour", "Minute",   "Second"}}]
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks for your help and time users: b.gatessucks and Sjoerd C. de Vries. Problem is solved. Thanks $\endgroup$ – Raymond... Dec 10 '12 at 23:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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