MATLAB: How to save a file with the actual date datesave I want to get the actual date in the following format YEAR,MONTH,DAY (YYYY_MM_DD). How can I do that? With date I get 03-Jul-2017. filename = 'SURENAME_YYYY_MM_DD.mat'; Best Answer If you want the current year, month, and day, try this:tv = datestr(now, 'yyyy_mm_dd');filename = sprintf('SURENAME_%s.mat',tv)filename = 'SURENAME_2017_07_02.mat'EDIT —To use my code with a datetime object, my ‘tv’ string becomes:tv = datetime('now', 'Format','yyyy_MM_dd');The rest of my code is unchanged.(It’s UTC-6 here.) Related SolutionsMATLAB: Convert excel date to datetime The format has to match exactly. Both of these work: S.textdata = '20-Nov-18 12:00:00 PM GMT';d1 = datetime(S.textdata(1:end-4), 'InputFormat', 'dd-MM-yy hh:mm:ss a', 'TimeZone', 'UTC')d2 = datetime(S.textdata, 'InputFormat', 'dd-MM-yy hh:mm:ss a ''GMT''', 'TimeZone', 'UTC')producing: d1 = datetime 20-Nov-2018 12:00:00d2 = datetime 20-Nov-2018 12:00:00Experiment to get the result you want. MATLAB: Convert Julian day to month datetick('x','mmm','keeplimits') % remove keepticks to see all months Jan-DecDunno about the 10e5 bit.. might be a bug remnant from pcolor..here is a linkt hat might helphttp://www.mathworks.com/matlabcentral/newsreader/view_thread/306718On my MAC 64 2012a, the following works the trick..clear alldepths = 1:1:12;temp = 0 + (20-0).*rand(8760,12);DateTime = datenum('2011-01-01 00:00','yyyy-mm-dd HH:MM'):1/24:... datenum('2011-12-31 23:57','yyyy-mm-dd HH:MM');DateTime = DateTime';pcolor(DateTime,depths,temp');shading interpdatetick('x','mmm','keeplimits');set(gcf,'Renderer','zbuffer') Related QuestionChange julian date to format timeDatetime problem of converting stringHow to convert numbers in the form yyyymm to dates in the form mm/dd/yyyyTransforming an integer vector into dates text vectorExtracting the year from a timestamp in a columnHow to convert yymmdd to dd/mm/yyyyMatlab imported excel time format change
Best Answer