How to convert this 'out_17-May-2021.xlsx' into 'out_20210517.xlsx'?
1 次查看(过去 30 天)
显示 更早的评论
Dear all,
How to convert this (below) into 'out_20210517'?
filename = sprintf('out_%s.xlsx', today('datetime'));
filename =
'out_17-May-2021.xlsx'
0 个评论
采纳的回答
Geoff Hayes
2021-5-17
Joanna - perhaps try using
datestr(now,'yyyymmdd')
instead/
2 个评论
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 Exchange 中查找有关 Dates and Time 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!