yyyymmdd to mm-dd-yyyy
Show older comments
I unzipped NOAA summary of the day data in matlab and imported it as a table and as a matrix. The datetime is in yyyymmdd (20100801) format. How can I convert it to mm-dd-yyyy(08-01-2010)?
4 Comments
per isakson
on 9 Nov 2017
Edited: per isakson
on 9 Nov 2017
"datetime" MM for month, not mm
>> t = datetime('20100801','InputFormat','yyyyMMdd')
t =
2010-08-01
>> t.Format = 'MM-dd-yyyy';
>> t
t =
08-01-2010
>>
Elias de Korte
on 1 Apr 2019
What if I have a time vector including hours: 2010121101 (2010, december, 11th 01:00:00: yyyymmddhh)?
Jan
on 1 Apr 2019
@Elias: According to the documentation you need HH, not hh:
t = datetime('2010080123','InputFormat','yyyyMMddHH')
t.Format = 'MM-dd-yyyy';
t
t =
08-01-2010
Akira Agata
on 1 Apr 2019
In addition, how about using datestr function? Like:
t = datetime('2010080123','InputFormat','yyyyMMddHH');
str = datestr(t,'mm-dd-yyyy');
>> str
str =
'08-01-2010'
Answers (0)
Categories
Find more on MATLAB 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!