change date to a Date String Format recognized by Matlab or seprate the hour from the date

1 view (last 30 days)
I have a data file which contains date and hour in the format of: "YYYY-MM-DDTHH:MM" As the format is not recognized by Matlab, I want to do one of the two solutions: - Change the format to a Matlab predefined one. - Or Separate the date from hours in two columns. Thank you for your help

Accepted Answer

Guillaume
Guillaume on 18 May 2015
Edited: Guillaume on 18 May 2015
I'm not sure what you mean by 'format not recognised' by matlab. As far as I know, all matlab functions dealing with date and time can have arbitrary format specified.
I'm not sure what the T stands for in your format, assuming it is a constant separator:
%using datetime
d = datetime('2015-05-18T09:35', 'InputFormat', 'yyyy-MM-dd''T''HH:mm')
%using datenum, note the format syntax is different
d = datenum('2015-05-18T09:35', 'yyyy-mm-ddTHH:MM')
For reading date from a file, textscan uses the same format specified as datetime for date inputs:
textscan(fid, '%{yyyy-MM-dd''T''HH:mm}D')

More Answers (0)

Categories

Find more on Dates and Time in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!