필터 지우기
필터 지우기

how to correct NaT in datetime

조회 수: 16 (최근 30일)
Elysi Cochin
Elysi Cochin 2017년 2월 27일
답변: Steven Lord 2017년 2월 27일
when i do as
st = datetime('13:00:00');
et = datetime('14:00:00');
t = datetime(cellTime);
tp = isbetween(t, st, et);
i have time between 13 and 14 in my cell array named cellTime, but when i process it as below,
t = datetime(cellTime, 'Format', 'hh:mm:ss');
i get all time after, 12pm as "NaT" i wanted to do as
t = datetime(cellTime, 'Format', 'hh:mm:ss');
because i need only the time value, if i dont use format, the date also comes, and that too todays date... any method to get only time and correct the NaT
  댓글 수: 1
Walter Roberson
Walter Roberson 2017년 2월 27일
What is the format of the entries in cellTime ?

댓글을 달려면 로그인하십시오.

채택된 답변

Steven Lord
Steven Lord 2017년 2월 27일
According to the definition of the Format property, 'hh' means "Hour, 12-hour clock notation using two digits". Instead you want to use 'HH', which means "Hour, 24-hour clock notation using two digits". Compare these two variables:
dt1 = datetime({'10:30', '15:36'}, 'InputFormat', 'hh:mm')
dt2 = datetime({'10:30', '15:36'}, 'InputFormat', 'HH:mm')

추가 답변 (1개)

Walter Roberson
Walter Roberson 2017년 2월 27일
t = datetime(cellTime, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss');
  댓글 수: 1
Elysi Cochin
Elysi Cochin 2017년 2월 27일
sir i read the time for an excel sheet to matlab... After reading i convert to datetime, if i give as
t = datetime(cellTime);
the time after 12:00 pm to 23:59 will be read corrrectly... but as i do not have given the date, todays date will be read.
but if i select only the time from the datetime using
t = datetime(cellTime, 'InputFormat', 'hh:mm:ss', 'Format', 'hh:mm:ss');
or
t = datetime(cellTime, 'Format', 'hh:mm:ss');
the date is not coming, that is correct, but the time after 12:00 pm to 23:59 will be NaT... i dont know why it is happening.... my excel data has more than 100 column values... but in a small cell array with 5 values, it is coming correctly.... i am not able to correct the error NaT

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by