datestr on UTC time '2016-12-19T08:00:00.000Z' failing
3 views (last 30 days)
Show older comments
Hi,
I am trying to convert ISO date and time string into cell array. My original data has a format of '2016-12-19T08:00:00.000Z'.
If I run the matlab code in the format below, it generates an error saying "Error using datestr (line 177) Cannot convert input into specified date character vector. DATENUM failed."
ds2 = datestr(out2{1,1}, 'yyyy-mm-ddTHH:MM:SSZ');
Can you find why is it generating an error? I think date formatting('yyyy-mm-ddTHH:MM:SSZ') is not correct.
0 Comments
Answers (2)
Walter Roberson
on 9 Feb 2017
Z is not one of the permitted letters for datestr. Although you can add characters like : or / to be matched literally, the literal matches are restricted to non-alphabetic characters.
If you have r2013b or later then datetime is recommended. Note the character codes are different with datetime to match international standards
5 Comments
Walter Roberson
on 11 Feb 2017
Could you give an example of a string that is not converted, and the time that you expect it to be converted to?
Peter Perkins
on 13 Feb 2017
As Walter says, it sounds like some (most?) of your strings are not in that format. If you have two formats, the solution is to do it in two steps, something like
d = datetime(s,'InputFormat',format1)
failed = isnat(d);
d(failed) = datetime(s(failed),'InputFormat',format2)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!