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

86 Ansichten (letzte 30 Tage)
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!

Akzeptierte Antwort

Stephan
Stephan am 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 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by