Time difference in 'HH:mm:ss,SSSSSS' format
26 views (last 30 days)
Show older comments
Hi
I have several absolute times in form of 'HH:mm:ss,SSSSSS' in a CSV (seperator is ; ).
What I need is the expired time in seconds, relative to the start time t0.
So I tried several ways:
1) Using datevec and etime
t0 = '15:30:25,123456'
t1 = '16:45:30,123457'
t0_vec = datevec(t0,'HH:mm:ss,SSSSSS') % Works only in 'HH:mm:ss'
t1_vec = datevec(t1,'HH:mm:ss,SSSSSS') % Works only in 'HH:mm:ss'
dt = etime(t1,t0);
This got me:
Error using matlab.internal.datetime.cnv2icudf (line 162)
Unrecognized second format. Format: HH:mm:ss,SSSSSS.
2) Using datetime and "-" operator
t0 = '15:30:25,123456'
t1 = '16:45:30,123457'
t0_datetime = datetime(t1,'InputFormat','HH:mm:ss,SSSSSS','Format','HH:mm:ss,SSSSSS')
t1_datetime = datetime(t1,'InputFormat','HH:mm:ss,SSSSSS','Format','HH:mm:ss,SSSSSS')
dt = t1-t0
This got me:
ans =
duration
05:32:08
(no fractional seconds.. also not when i exportet it )
Thanks for your help!
0 Comments
Accepted Answer
Steven Lord
on 23 Feb 2021
t0 = '15:30:25,123456'
t1 = '16:45:30,123457'
theFormat = 'hh:mm:ss.SSSSSS';
timeStart = duration(replace(t0, ',', '.'), 'InputFormat', theFormat, 'Format', theFormat)
timeEnd = duration(replace(t1, ',', '.'), 'InputFormat', theFormat, 'Format', theFormat)
elapsed = timeEnd - timeStart
0 Comments
More Answers (0)
See Also
Categories
Find more on Time Series Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!