필터 지우기
필터 지우기

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