MATLAB: How to convert numbers in the form yyyymm to dates in the form mm/dd/yyyy

date conversiondatesnumbers to dates

I have a vector of dates that are not recognized as dates, but numbers. I need this vector to be converted to the form mm/dd/yyyy. For example, the first entry is 192604 and I need it to read 04/01/1926. I have tried multiple conversion functions but they all require the data to already be formatted as a date. How would I do this?

Best Answer

Try this:
numerical_dates = 192604 : 192609;
dates = datetime(fix(numerical_dates/100),rem(numerical_dates,100), ones(size(numerical_dates)), 'Format','MM/dd/yyyy');