MATLAB: Converting Date: ’09/07/2012 23:22:01′ into filename friendly format

convertdatefilenameformat

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

Best Answer

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