필터 지우기
필터 지우기

Converting Date: '09/07/2012 23:22:01' into filename friendly format

조회 수: 3 (최근 30일)
Aadil
Aadil 2012년 7월 31일
I have script that creates a variable filename for output pdf files, I want to insert dates into the filename but cannot as they're not in the correct format.
How can I convert this date and time 09/07/2012 23:22:01 into just 09_07_2012 or 09072012 - whilst ignoring the time?
Thanks

채택된 답변

Adrian
Adrian 2012년 7월 31일
Hello,
You could try to use the datestr(now,30)command. It will give you the (ISO 8601)'yyyymmddTHHMMSS'format. Please see the datestr help.
You can use datestr(now,'ddmmyyyy') to get something like '31072012'. You can use datestr(now,'ddmmmyyyy') to get something like '31Jul2012'.
I hope this will help you.
Best regards, Adrian

추가 답변 (1개)

Jan
Jan 2012년 7월 31일
Str = '09/07/2012 23:22:01';
NewStr = Str([1,2,3,4,5,6,7,8]); % '09072012'
This is much faster than the very powerful date conversion routines.
I'd prefer the other direction '20120709', because then the temporal order equals the alphabetical order and sort can handle this directly.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by