How to decipher date formats?
Ältere Kommentare anzeigen
My date columns stored in Excel can have various formats like the below:
'9/1/19'
'31-Dec-2020'
I'm reading them into Matlab using readtable and want to export them into a txt file with the format of '31-Dec-2020' for all of them.
How do I read them correctly in a holistical way?
Thanks
2 Kommentare
Guillaume
am 22 Mär. 2020
I don't really understand what you mean by "Is it possible to get their datenum correctly in a holistical way?".
You haven't even explained how you get the excel data into matlab. Hopefully, you're using readtable or similar and not xlsread.
Secondly, why would you be using datenum when the much better datetime has been available since 2014b?
Leon
am 22 Mär. 2020
Akzeptierte Antwort
Weitere Antworten (1)
Steven Lord
am 22 Mär. 2020
0 Stimmen
It depends. Is that first date supposed to be:
- the 9th of January, 2019 (day/month/year, increasing order of size of units)
- the 1st of September, 2019 (month/day/year)
- (less commonly) the 19th of January, either year 9 AD or year 2009 (sometimes people abbreviate the release numbers of MATLAB, referring to 9a instead of R2009a, so interpreting 9 as 2009 has some precedent) (year/month/day, decreasing order of size of units)
- or something else?
But I agree with Guillaume. Don't try to read these in as serial date numbers. Read them in as text and convert them into date and time objects using datetime, specifying the InputFormat option. See the section of the datetime documentation page that describes the meaning of the various parts of the Format option (which also work for the InputFormatt option.) If you use something like readtable you can combine those two steps.
1 Kommentar
Leon
am 22 Mär. 2020
Kategorien
Mehr zu Time Series Objects finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!