Instruction:
FromDateString["20240811222725", {"Year", "Month", "Day", "Hour", "Minute", "Second"},TimeZone->"UTC"]
Result:
FromDateString: String 20240811222725 cannot be interpreted as a date in the specified format.
What am I doing wrong?
Instruction:
FromDateString["20240811222725", {"Year", "Month", "Day", "Hour", "Minute", "Second"},TimeZone->"UTC"]
Result:
FromDateString: String 20240811222725 cannot be interpreted as a date in the specified format.
What am I doing wrong?
I think FromDateString expects at least some structure in the string to indicate that it’s a date, specifically some delimiters.
Yuck. I guess I can call out to Python or the shell to reform it into a string that Wolfram can interpret…
You could reform it within Mathematica.
FromDateString command dosen’t take your format date.
In Mathematica:
DATE = "20240811222725";
DateObject[{StringTake[DATE, {1, 4}] // ToExpression,
StringTake[DATE, {5, 6}] // ToExpression,
StringTake[DATE, {7, 8}] // ToExpression,
StringTake[DATE, {9, 10}] // ToExpression,
StringTake[DATE, {11, 12}] // ToExpression,
StringTake[DATE, {13, 14}] // ToExpression}]
(*Gives date*)
Quicker (or, rather, easier for this amateur) to use an ExternalEvaluate of strptime() in Python than trying to split the string all up in Wolfram. ![]()
Or, quicker:
ExternalEvaluate["Python","import datetime; datetime.datetime.strptime('20220811123456","%Y%m%d%H%M%S")"]
Try setting the delimiters explicitly, i.e.:
FromDateString["20240811222725", <|
"Elements" -> {"Year", "Month", "Day", "Hour", "Minute", "Second"},
"Delimiters" -> {""}|>, TimeZone -> "UTC"]
the code can by simplified more:
DateObject[ToExpression@StringTake["20240811222725", Join[{{1, 4}}, Partition[Range[5, 14], 2]]]]
Regards M.I.