I have a variable T.Date with 5173x 1 datetime, '04/04/2018' '05/04/2018' etc...
when i use the code
Date= datestr(T.Date,'dd/MM/yyyy');
or
formatOut = 'dd/MM/yyyy'
Date= datestr(T.Date, formatOut)
I get 5173 x 10 char '04/00/2018' and so on for all the dates. The month is 00 for every output.
why is this happening and what can I do to fix this?

1 commentaire

Stephen23
Stephen23 le 20 Nov 2018
Modifié(e) : Stephen23 le 20 Nov 2018
What MATLAB version are you using?

Connectez-vous pour commenter.

 Réponse acceptée

Stephen23
Stephen23 le 20 Nov 2018
Modifié(e) : Stephen23 le 20 Nov 2018

0 votes

If T.Date really is a datetime array, then use string to convert it to a string array. Make sure that you have set the datetime's format property first:
T.Date.format = 'dd/MM/yyyy'
S = string(T.Date)
Or use cellstr:
C = cellstr(T.Date)
Or use char:
C = char(T.Date)

1 commentaire

Aedin McAleer
Aedin McAleer le 20 Nov 2018
This worked perfectly, thank you.
I use Matlab 2018a

Connectez-vous pour commenter.

Plus de réponses (1)

madhan ravi
madhan ravi le 20 Nov 2018

0 votes

Use datetime
str='04/04/2018'
Date= datetime(str,'format','dd/MM/yyyy')

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by