Convert serial number dates to month and year

조회 수: 8 (최근 30일)
Keturah Palma
Keturah Palma 2018년 7월 23일
편집: Paolo 2018년 7월 23일
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
Keturah Palma
Keturah Palma 2018년 7월 23일
thank you so much
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