MATLAB: Transforming HH:mm:SS to ‘dd.MM.yy HH:mm:SS’ and loosing seconds

convertMATLABtime

>> time = datestr(seconds(duration),'HH:MM:SS')
time =
'02:59:57'
>> date_and_time = datetime(time, 'ConvertFrom', 'datenum', 'Format', 'dd.MM.yy HH:mm:SS')
date_and_time =
datetime
22.07.19 02:59:00
I would like to add current date to the 'time'. Why do I loose the 57 seconds when I do this transformation, and how to do it correctly?
Many thanks!

Best Answer

"I would like to add current date to the 'time'"
Sure, that is easy, by just adding a duration object to a datetime object.
You do not write what class the very badly-named duration is, but the simplest solution is to add a duration array to the datetime object of the current time:
>> D = seconds(1375.143) % a duration object
D =
1375.1 secs
>> T = datetime() % a datetime object (current time)
T =
22-Jul-2019 13:19:37
>> X = D+T % add them together!
X =
22-Jul-2019 13:42:32