How to convert Data from 'yyyyMMddhhmm' format to datetime format
Show older comments
Hello
I have been searching for a solution to converting my data from a number value with a 'yyyyMMddhhmm' format to a datetime format. Previously i attempted the following:
dtm = datetime(HS_Date,'InputFormat','yyyyMMddHHmm');
where HS_date is a matrix of 1x52561 double values, the data is from 202201010000 to 202301010000.
But i get an error message saying the following: "Error using Datetime (line 588) Numeric input data must be a matrix with three or six columns, or else three, six, or seven separate numeric arrays. You can also create datetimes from a single numeric array using the 'ConvertFrom' parameter."
The ConvertFrom parameter only offers the yyyMMdd format and is not an viable option.
I am unsure if i am defining anything wrongly, or if i need to format my data differently to make the function work.
note: my data is showcased in the program as 202201010000.000, but i cannot change or remove the decimals using the round or fix function.
Kind regards
Accepted Answer
More Answers (1)
dstr = ["202201010000.000" "202301010000.000"]
t = datetime(dstr,'InputFormat','yyyyMMddHHmm.SSS')
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!