필터 지우기
필터 지우기

datestr problem with minutes

조회 수: 3 (최근 30일)
Vanessa
Vanessa 2017년 6월 29일
댓글: Andrei Bobrov 2017년 6월 29일
Hello everyone,
I'm encountering a problem with date conversion. I have a dataset column with dates in '1/5/2017 12:10:00AM' form and I want to convert it into '2017-05-01 00:10:00' format. I used the datestr function but the minutes are incorrect. All rows return with 00 minutes.
How can I fix this?
Thank you in advance, Vanessa
  댓글 수: 3
Vanessa
Vanessa 2017년 6월 29일
kwhm.date=datestr(kwhm.date,'yyyy-mm-dd HH:MM:SS');
date '1/5/2017 12:10:00AM' '1/5/2017 12:15:00AM' '1/5/2017 12:20:00AM' etc
Andrei Bobrov
Andrei Bobrov 2017년 6월 29일
Dear Vanessa! please accept the answers that solved your problems.

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

답변 (2개)

Walter Roberson
Walter Roberson 2017년 6월 29일
t = datenum('1/5/2017 12:10:00AM' );
datestr(t, 'YYYY-mm-DD HH:MM:ss')

Andrei Bobrov
Andrei Bobrov 2017년 6월 29일
편집: Andrei Bobrov 2017년 6월 29일
a = datetime('1/5/2017 12:10:00AM','I','dd/MM/yyyy hh:mm:ssa','F','yyyy-MM-dd HH:mm:ss')
  댓글 수: 4
Vanessa
Vanessa 2017년 6월 29일
Thank you very much!!!
Andrei Bobrov
Andrei Bobrov 2017년 6월 29일
a = {'1/5/2017';
'1/5/2017 12:10:00AM';
'1/5/2017 12:15:00AM';
'1/5/2017 12:20:00AM';
'2/5/2017'};
t = ~cellfun(@isempty,regexp(a,'\d{4}$'));
a(t) = cellfun(@(x)[x,' 00:00:00AM'],a(t),'un',0);
out = datetime(a,'I','dd/MM/yyyy hh:mm:ssa','F','yyyy-MM-dd HH:mm:ss')

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

카테고리

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