Azzera filtri
Azzera filtri

Converting a string to datenum format

18 visualizzazioni (ultimi 30 giorni)
Malavan Subramaniam
Malavan Subramaniam il 28 Ott 2019
Risposto: Shubham Gupta il 29 Ott 2019
So I have a dataset that presents dates as strings (example: "2011-08-31T21:16:01.948Z"). My question is how do I convert this string into a datenum format? I feel like the 'T' and the 'Z' might make things more complicated. Also, how would I do this for every date in the dataset?
I am very new and bad with Matlab, so please provide as simple as an explanation that you can! That would be greatly appreciated! :)
Thank you!!

Risposte (2)

Walter Roberson
Walter Roberson il 29 Ott 2019
Use datetime() to parse the string and then datenum() the results.
In most cases you are better just using the datetime object without datenum()

Shubham Gupta
Shubham Gupta il 29 Ott 2019
Try:
DateString = '2011-08-31T21:16:01.948Z';
RepExp = '[a-zA-Z]'; % want to replace any alphabet, indicated by [a-zA-Z]
RepStr = ' '; % Replace by blank space
DateString_Up = regexprep(DateString,RepExp,RepStr); % Updated date string
DateNumber = datenum(DateString_Up); % Convert it to datenum
Let me know if you have doubts !

Categorie

Scopri di più su Dates and Time in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by