create yyyymm variable from date

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.

请先登录,再进行评论。

更多回答(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