Difference between two time values in minutes

41 ビュー (過去 30 日間)
Mesfin Ibrahim
Mesfin Ibrahim 2022 年 2 月 11 日
コメント済み: Stephen23 2022 年 2 月 11 日
I have two time point and was trying to calculate their difference to be converted to minutes.
t1 = 08/24/2010 13:21:47.030
t2 = 08/24/2010 14:13:09.118
I tried caldiff, duration, datetime and didn't work. Can you help?
dt = between(t1,t2,"minutes")
  1 件のコメント
Stephen23
Stephen23 2022 年 2 月 11 日
Do NOT use deprecated DATENUM or DATEVEC or DATESTR.
t1 = '08/24/2010 13:21:47.030';
t2 = '08/24/2010 14:13:09.118';
dt = datetime([t1;t2],'InputFormat','M/d/u H:m:s.SSS')
dt = 2×1 datetime array
24-Aug-2010 13:21:47 24-Aug-2010 14:13:09
d = dt(2)-dt(1)
d = duration
00:51:22
m = minutes(d)
m = 51.3681

サインインしてコメントする。

回答 (1 件)

Arif Hoq
Arif Hoq 2022 年 2 月 11 日
編集済み: Arif Hoq 2022 年 2 月 11 日
t1 = {'08/24/2010 13:21:47.030'};
t2 = {'08/24/2010 14:13:09.118'};
dt= diff(datenum([t1;t2]))*24*60
dt = 51.3681
% to get the second
second=diff(datenum([t1;t2]))*24*60*60
second = 3.0821e+03

カテゴリ

Help Center および File ExchangeDates and Time についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by