Effacer les filtres
Effacer les filtres

Unable to convert the text to datetime using the format: 'dd-MM-yyyy hh:mm'

101 vues (au cours des 30 derniers jours)
Hello,
I am trying to convert a my data set in the format seen below into a datetime:
t = datetime(x([9:2445], 1), 'InputFormat', 'dd-MM-yy hh:mm', 'Format', 'hh:mm');
If the data was collected AM, i.e. 22-9-2020 10:35, then the data is converted using date time.
However, if the data was collected PM, i.e. 22-9-2020 15:48, then Matlab gives the error:
Unable to convert the text to datetime using the format: 'dd-MM-yyyy hh:mm'
This is how I load the data:
[x y z] = xlsread(['C:\Users\veerl\Documents\RM HMS\Year 2\Data\Data Collection\nw1\nw1_cosinuss.xlsx']); x = y;
t = datetime(x([9:2445], 1), 'InputFormat', 'dd-MM-yy hh:mm', 'Format', 'hh:mm');
cosinuss.nw1 = struct('Time', t, 'Temperature', str2double(y([9:2445], 3)));
Can someone see where my mistake in understanding the format of the date is? If so please could you provide a solution that will help me read this format of string into a datetime?
Cheers!

Réponse acceptée

Stephan
Stephan le 25 Nov 2020
datetime('22-9-2020 10:35','InputFormat','dd-MM-yy HH:mm')
datetime('22-9-2020 15:48','InputFormat','dd-MM-yy HH:mm')
ans =
datetime
22-Sep-2020 10:35:00
ans =
datetime
22-Sep-2020 15:48:00
  3 commentaires
Stephan
Stephan le 25 Nov 2020
Note that i used
HH:mm
instead of
hh:mm
Veerle Kohlen
Veerle Kohlen le 25 Nov 2020
Thanks for your help!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB 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!

Translated by