Combine date and duration into single datetime column

조회 수: 16 (최근 30일)
Enrico Gambini
Enrico Gambini 2022년 2월 21일
댓글: Star Strider 2022년 2월 21일
Hello!
I have a vector containing the data in a datetime format (MM/dd/uuuu)and the vector containing the hours of the days in duration format(hh:mm:ss)
I want to combine the two vectors in order to get a single datetime vector having date and hour togheter.
I tried this code but it seems that is not working:
new_datetime=date+hour;

채택된 답변

Star Strider
Star Strider 2022년 2월 21일
Add them —
DT = datetime(repmat([2018 01 01], 5, 1))
DT = 5×1 datetime array
01-Jan-2018 01-Jan-2018 01-Jan-2018 01-Jan-2018 01-Jan-2018
DU = duration('00:00:00') + 5*minutes(0:4)'
DU = 5×1 duration array
00:00:00 00:05:00 00:10:00 00:15:00 00:20:00
Combined = DT + DU
Combined = 5×1 datetime array
01-Jan-2018 00:00:00 01-Jan-2018 00:05:00 01-Jan-2018 00:10:00 01-Jan-2018 00:15:00 01-Jan-2018 00:20:00
.
  댓글 수: 8
Enrico Gambini
Enrico Gambini 2022년 2월 21일
I really don't know how this is possible. I simply exported the two columns of the table and they have been automatically merged... hence, I will use this datetime in table "T" for my work.
Neverthless, your answer should have worked and I'm gonna accept it.
Thank you for your patience!
Star Strider
Star Strider 2022년 2월 21일
Thank you!
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by