how to find time difference between 2 times , in milliseconds.

207 ビュー (過去 30 日間)
rnd rnd
rnd rnd 2018 年 10 月 23 日
コメント済み: Peter Perkins 2018 年 10 月 31 日
So I have a cell with a column with data like this :
I want to find out the time differences lets say between 2 rows,
I tried it like this: etime(datevec(datenum(c{1,2}{1,1})), datevec(datenum(c{1,2}{2,1})))
it worked great when I did not have milliseconds, my data was like this:
but if I add data with milliseconds it gives me a wrong answer.
I want the result in milliseconds (also in seconds if possible).


jonas 2018 年 10 月 23 日
編集済み: jonas 2018 年 10 月 23 日
Just work with duration format.
td = duration(t,'inputformat','hh:mm:ss.SSS');
out = milliseconds(diff(td))
ans =
The only problem is if your time is displaying time of day, in which case you need to use datetime instead, or else you will get a large spike in your time difference at midnight.
  10 件のコメント
Peter Perkins
Peter Perkins 2018 年 10 月 31 日
In earlier versions, you can convert from text to duration using datevec, or using datetime+timeofday, but perhaps even easier, you can use text2duration on the FEX.


その他の回答 (1 件)

madhan ravi
madhan ravi 2018 年 10 月 23 日 convert the time array to milliseconds as suggested in the link and then do the calculations

Community Treasure Hunt

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

Start Hunting!

Translated by