Adding datestr to filename producing odd results
Show older comments
Hello,
I am trying to have my data saved as an xls file with the date included.
formatSpec = 'Run_%i_%i.xlsx';
A1 = Run; %in this case I'd declared it to be 37
A2 = datestr(now, 'ddmmmyy');
str = sprintf(formatSpec,A1,A2)
While I can save as "Run_37.xls" and it works. I can't get the date in there.
This is what appears in the cmd window for the variable str, which is what I use in xlswrite(..)
str =
Run_37_48.xlsxRun_51_77.xlsxRun_97_121.xlsxRun_49_54.xlsx
I have no idea what all the extra characters are after Run_37... My variable A2 does produce 03May16.
Thanks for your attention!
2 Comments
The format string makes no sense: the date is a string, but you use %i for the date variable, whereas it should be %s (because the date variable is a string, not an integer):
'Run_%i_%s.xlsx'
Also note that it would be much better to use an ISO 8601 date format, such as yyyy-mm-dd, because these sort correctly into chronological order.
jonathan ahn
on 4 May 2016
Accepted Answer
More Answers (0)
Categories
Find more on Spreadsheets in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!