How to convert this 'out_17-May-2021.xlsx' into 'out_20210517.xlsx'?

1 回表示 (過去 30 日間)
Joanna Przeworska
Joanna Przeworska 2021 年 5 月 17 日
コメント済み: Siddharth Bhutiya 2021 年 5 月 19 日
Dear all,
How to convert this (below) into 'out_20210517'?
filename = sprintf('out_%s.xlsx', today('datetime'));
filename =
'out_17-May-2021.xlsx'

採用された回答

Geoff Hayes
Geoff Hayes 2021 年 5 月 17 日
Joanna - perhaps try using
datestr(now,'yyyymmdd')
instead/
  2 件のコメント
Joanna Przeworska
Joanna Przeworska 2021 年 5 月 17 日
Of course! It works. Thanks a lot Geoff.
Best regards,
JP
Siddharth Bhutiya
Siddharth Bhutiya 2021 年 5 月 19 日
You could also do it using datetime by specifying the display format using the Format name-value pair.
>> filename = sprintf('out_%s.xlsx', datetime('now','Format','yyyyMMdd'))
filename =
'out_20210519.xlsx'
This seems like a simple workflow so it might not matter, but if you are working with dates and times, datetime would be recommended over using something like datestr or datenum.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by