Convert serial number dates to month and year

7 vues (au cours des 30 derniers jours)
Keturah Palma
Keturah Palma le 23 Juil 2018
Modifié(e) : Paolo le 23 Juil 2018
I have a date (736473) that i want to convert to month and year. How do i go about doing that ?

Réponse acceptée

Paolo
Paolo le 23 Juil 2018
Modifié(e) : Paolo le 23 Juil 2018
mydate = datetime(736473,'ConvertFrom','datenum','Format','yyyy-MM')
  5 commentaires
Keturah Palma
Keturah Palma le 23 Juil 2018
thank you so much
Paolo
Paolo le 23 Juil 2018
Modifié(e) : Paolo le 23 Juil 2018
That's very true Walter, datenum is indeed redundant. I should probably get some sleep... I'll edit.

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 23 Juil 2018
dv = datevec(736473);
year = dv(:,1);
month = dv(:,2);
  1 commentaire
Walter Roberson
Walter Roberson le 23 Juil 2018
If you want the result as a cell array of character vectors, then you can use
datestr(736473:736475,'yyyy-mm')
for example.
Note that for datestr(), the coding for month is lower-case m, but that for the newer datetime(), the coding for month is upper-case M.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by