How to convert numbers in the form yyyymm to dates in the form mm/dd/yyyy
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jack Bratton
le 5 Mar 2018
Réponse apportée : Peter Perkins
le 8 Mar 2018
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?
0 commentaires
Réponse acceptée
Star Strider
le 5 Mar 2018
Try this:
numerical_dates = 192604 : 192609;
dates = datetime(fix(numerical_dates/100),rem(numerical_dates,100), ones(size(numerical_dates)), 'Format','MM/dd/yyyy');
2 commentaires
Plus de réponses (1)
Peter Perkins
le 8 Mar 2018
Assuming the values you have are really numeric values...
There is a "canned" conversion form yyyymmdd, but regrettably not one from yyyymm. But easy to make yyyymmdd work:
>> x = 192604;
>> datetime(x*100+1,'ConvertFrom','yyyymmdd','Format','MM/dd/yyyy')
ans =
datetime
04/01/1926
0 commentaires
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!