Combine date and duration into single datetime column

10 views (last 30 days)
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:

Accepted Answer

Star Strider
Star Strider on 21 Feb 2022
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

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!