Seperate yyyymm to mm-yyyy

조회 수: 3 (최근 30일)
Megan Mirkhanian
Megan Mirkhanian 2020년 1월 20일
편집: Stephen23 2020년 1월 21일
I uploaded a table with one of the columns showing yyyymm,
How do I get tha column in the mm-yyyy format

답변 (1개)

Star Strider
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
Star Strider
Star Strider 2020년 1월 21일
@Walter — Thank you!
Stephen23
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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by