How do I get MATLAB to read a long number as a date and time?
3 views (last 30 days)
So I have a long number which represents a time in this format mmddyyyyHHMMSS. Where mm is 2 digit month, dd is 2 digit day, yyyy is 4 digit year, HH is 2 digit hour, MM is 2 digit minute, and SS is 2 digit second. Example: 11142021092415 which is November 14th 2021 at 9:24:15.
How can I turn that long number into a date and time that matlab would understand, this is ultimately for the purpose of plotting a temperature value based on this time. The time was recorded this way because it spans over a few days.
I've tried looking into the datetime function and the like but with my level of skill and understanding, I am not sure how to execute it correctly. Greatly appreciate any help.
Cris LaPierre on 17 May 2022
Edited: Cris LaPierre on 17 May 2022
Convert your numbers to strings, and then use datetime to convert it to a time.
% original data
t = [11142021092415; 7242020093039];
% convert to string
T = string(t);
% Convert to datetime
d = datetime(T,'InputFormat','MMddyyyyHHmmss')
You can also set the display format if you want.
d.Format = 'MMMM dd, yyyy H:mm:ss'