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

1 Ansicht (letzte 30 Tage)
Dear all,
How to convert this (below) into 'out_20210517'?
filename = sprintf('out_%s.xlsx', today('datetime'));
filename =
'out_17-May-2021.xlsx'

Akzeptierte Antwort

Geoff Hayes
Geoff Hayes am 17 Mai 2021
Joanna - perhaps try using
datestr(now,'yyyymmdd')
instead/
  2 Kommentare
Joanna Przeworska
Joanna Przeworska am 17 Mai 2021
Of course! It works. Thanks a lot Geoff.
Best regards,
JP
Siddharth Bhutiya
Siddharth Bhutiya am 19 Mai 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by