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 Center および File ExchangeDescriptive 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