How to get difference between two time values ?
12 次查看(过去 30 天)
显示 更早的评论
How we will get difference between the below times. I tried with caldiff, diff, substraction commands its not working . Please help me if any one knows
0 个评论
采纳的回答
Dennis
2019-5-10
You can use etime, but you need to convert your strings first. I hope this helps:
a=datetime
pause(5)
b=datetime
a=datevec(a);
b=datevec(b);
etime(b,a)
0 个评论
更多回答(1 个)
Peter Perkins
2019-5-14
Don't use etime. Use datetimes. Haritha, without more info it's hard to tell, but it looks like your "data" is a cellarray of char vectors. You have to start with the right kind of data. Do this:
>> c
c =
4×1 cell array
{'17-Apr-2019 11:40:10'}
{'17-Apr-2019 11:40:12'}
{'23-Apr-2019 16:11:41'}
{'23-Apr-2019 16:11:47'}
>> t = datetime(c)
t =
4×1 datetime array
17-Apr-2019 11:40:10
17-Apr-2019 11:40:12
23-Apr-2019 16:11:41
23-Apr-2019 16:11:47
>> caldiff(t) % calendar unit diffs
ans =
3×1 calendarDuration array
0h 0m 2s
6d 4h 31m 29s
0h 0m 6s
>> diff(t) % exact time times
ans =
3×1 duration array
00:00:02
148:31:29
00:00:06
>> t - t(1) % offset from first time
ans =
4×1 duration array
00:00:00
00:00:02
148:31:31
148:31:37
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!