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 =

채택된 답변

Geoff Hayes
Geoff Hayes 2021년 5월 17일
Joanna - perhaps try using
  댓글 수: 2
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 =
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.

댓글을 달려면 로그인하십시오.

추가 답변(1개)

VBBV 2021년 5월 17일
%if true
k = datestr(filename(5:15),'yyyymmdd')
You can use filename to reconstruct the date



Community Treasure Hunt

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

Start Hunting!

Translated by