Transforming an integer vector into dates text vector

21 vues (au cours des 30 derniers jours)
Mohamed Larabi
Mohamed Larabi le 28 Mai 2018
Commenté : Star Strider le 28 Mai 2018
I am having a vector corresponding to dates in the following format yyyymmdd, ie for December 24th, 2010 it is 20101224. How can I transform this vector of integers into text dates in the following format 'mm-dd-yyyy'?

Réponse acceptée

Star Strider
Star Strider le 28 Mai 2018
Assuming your original vector is numeric, there are two options:
dates = [20101224; 20101225; 20101226];
ds1 = datestr(datenum(num2str(dates), 'yyyymmdd'), 'mm-dd-yyyy'); % Use ‘datenum’ & ‘datestr’
ds2 = datetime(num2str(dates), 'InputFormat','yyyyMMdd', 'Format','MM-dd-yyyy'); % Use ‘datetime’
  2 commentaires
Mohamed Larabi
Mohamed Larabi le 28 Mai 2018
Thank you very much. It is perfect!
Star Strider
Star Strider le 28 Mai 2018
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

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

Tags

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by