Convert serial number dates to month and year

4 次查看(过去 30 天)
I have a date (736473) that i want to convert to month and year. How do i go about doing that ?

采纳的回答

Paolo
Paolo 2018-7-23
编辑:Paolo 2018-7-23
mydate = datetime(736473,'ConvertFrom','datenum','Format','yyyy-MM')
  5 个评论
Paolo
Paolo 2018-7-23
编辑:Paolo 2018-7-23
That's very true Walter, datenum is indeed redundant. I should probably get some sleep... I'll edit.

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
Walter Roberson 2018-7-23
dv = datevec(736473);
year = dv(:,1);
month = dv(:,2);
  1 个评论
Walter Roberson
Walter Roberson 2018-7-23
If you want the result as a cell array of character vectors, then you can use
datestr(736473:736475,'yyyy-mm')
for example.
Note that for datestr(), the coding for month is lower-case m, but that for the newer datetime(), the coding for month is upper-case M.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by