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

101 次查看(过去 30 天)
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!

采纳的回答

Stephan
Stephan 2020-11-25
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by