Format of datestr() changes
이전 댓글 표시
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
Walter Roberson
2017년 10월 12일
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
2017년 10월 12일
Walter Roberson
2017년 10월 12일
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
2017년 10월 12일
Walter Roberson
2017년 10월 12일
Have you attempted doing the reading using readtable() and getting datetime objects instead of having to convert yourself ?
Peter Perkins
2017년 10월 13일
As Walter says, readtable is a much better choice for reading dates from an Excel file than xlsread.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Time Series Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!