MATLAB: Mtheyy date to matlab date dates Hi there. I have a column vector with dates on the following format: yyyymm E.g. [199001, 199002, 199003 …]' They are all the last trading day of the month. How can I transform them into matlab serial date numbers? Thanks Best Answer x = [199001, 199012, 199003]';% Calculate year and monthmm = rem(x,100);yyyy = (x-mm)./100;% get last business day (Financial Toolbox Req'd)last_bus_day = lbusdate(yyyy,mm) Related SolutionsMATLAB: Function for day of the year Introduced in R2014b>> day( datetime('07-Jan-2017', 'InputFormat', 'dd-MMM-yyyy' ), 'dayofyear' )ans = 7"accounting for leap years" If not, shame on The MathWorks!>> day( datetime('01-Mar-2017', 'InputFormat', 'dd-MMM-yyyy' ), 'dayofyear' )ans = 60>> day( datetime('01-Mar-2016', 'InputFormat', 'dd-MMM-yyyy' ), 'dayofyear' )ans = 61 MATLAB: Date question d1 = datevec(date());datestr([d1(1)-1 d1(2)+6 1 0 0 0])This uses the trick that you cannot go negative on months, but you can go back a year and forward 6 months from there.Do not use -6*30 as that does not take in to account the length of months and will not handle leap-years properly.ps: today is Feb 17, 2011 not 2010 :) Related QuestionConverion of a dateDate ConversionUsing datenum over several yearsDatestr format in lower caseDate formats
Best Answer