export CSV file with timestamp in filename

4 views (last 30 days)
I want to export some data using writetable into a .csv file but I also want a timestamp in the name of the .csv file. I have been able to export the data to a .csv file and I have been able to export the data with the timestamp but ONLY as a .txt file. Any advice??

Accepted Answer

Star Strider
Star Strider on 2 Feb 2015
I’m not certain exactly what you want, but this will get you started:
filename = sprintf('CSV File %s.csv', datestr(now));
produces:
filename =
CSV File 02-Feb-2015 10:16:58.csv
You can specify the format of the timestamp with the ‘formatOut’ parameter of datestr, for example:
filename = sprintf('CSV File %s.csv', datestr(now, 'dd.mm.yyyy HH:MM'))
produces:
filename =
CSV File 02.02.2015 10:20.csv
  2 Comments
alexandra kaufhold
alexandra kaufhold on 2 Feb 2015
Thank you! Worked just as I had hoped. I was using fprintf so that was the issue. Thank you!!!!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!