Seperate yyyymm to mm-yyyy
2 次查看(过去 30 天)
显示 更早的评论
I uploaded a table with one of the columns showing yyyymm,
How do I get tha column in the mm-yyyy format
0 个评论
回答(1 个)
Star Strider
2020-1-20
Try this:
ym = [201910
201911
201912
202001]; % Numeric (?)
yms = compose('%6d',ym)
my = datetime(yms, 'InputFormat','yyyymm', 'Format','mm-yyyy')
producing:
my =
4×1 datetime array
10-2019
11-2019
12-2019
01-2020
6 个评论
Stephen23
2020-1-21
编辑:Stephen23
2020-1-21
Note that for datetime objects lowercase mm represents minutes and uppercase MM represents months:
It is very unlikely that the data really encoded a timestamp of "yearminute" which should then be displayed as "minute-year". Because the datetime format capitalization is not very intuitiive, it is worth reading/checking the datetime documentation every time, to easily avoid these kind of bugs.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!