Format of datestr() changes
Show older comments
Hi,
I'm was using datestr() to get the date string instead of number, when I realised that the format of the string changes. I've data over a year with a minute interval.
January-April, June-September and November show the date like this: dd.mm.yyyy HH:MM
while May, October and December show it like this: dd-mmm-yyyy HH:MM:SS
Why is that?
6 Comments
Walter Roberson
on 12 Oct 2017
I am not seeing it?
>> datestr(now)
ans =
'12-Oct-2017 03:20:10'
>> datestr(now-30)
ans =
'12-Sep-2017 03:20:26'
>> datestr(now-60)
ans =
'13-Aug-2017 03:20:33'
How did you create the numeric data that you are using with datestr() ?
Helma Maria Tróndheim
on 12 Oct 2017
Walter Roberson
on 12 Oct 2017
Were the dates definitely given as strings in the excel files? The typical way that date fields are stored in excel is in excel numeric date format.
When you were importing, did you import only partial months at a time? When parsing date strings if there are only partial months, it might guess wrong about whether a field is numeric or numeric day.
Is it possible that the files themselves had different date string formats?
Ummmm.. writetable is typically better at handling output of datetime objects rather than exporting numeric dates, unless it is told which columns are datenum. But perhaps you had strings already in the date fields when you did the writetable() ?
Helma Maria Tróndheim
on 12 Oct 2017
Walter Roberson
on 12 Oct 2017
Have you attempted doing the reading using readtable() and getting datetime objects instead of having to convert yourself ?
Peter Perkins
on 13 Oct 2017
As Walter says, readtable is a much better choice for reading dates from an Excel file than xlsread.
Answers (0)
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!