create yyyymm variable from date

조회 수: 6 (최근 30일)
alpedhuez
alpedhuez 2020년 6월 29일
댓글: Star Strider 2020년 6월 30일
I have a date variable. I want to create yyyymm from the date variable. I can use the year function and the month function to extract year and month. I would like to know how one can create yyyymm variable.
  댓글 수: 3
alpedhuez
alpedhuez 2020년 6월 30일
Thank you. It is datetime. It is like 1/1/2020. Want to extract just yyyymm out of it.
alpedhuez
alpedhuez 2020년 6월 30일
yyyymmdd=yyyymmdd(Date);
yyyymm=floor(yyyymmdd./100);

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2020년 6월 30일
Try this:
dt = '1/1/2020';
Out = datetime(dt, 'InputFormat','MM/dd/yyyy', 'Format','yyyyMM')
producing:
Out =
datetime
202001
.
  댓글 수: 3
alpedhuez
alpedhuez 2020년 6월 30일
Thank you. Let me work on it.
Star Strider
Star Strider 2020년 6월 30일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics and Visualization에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by