How to substract time from another time after midnight?
조회 수: 2 (최근 30일)
이전 댓글 표시
So I have start time and end time of trip (in string) in my data, but sometimes end time exceeds midnight, for example:
start_time = "18:30";
end_time = "00:30";
How can correctly substract them to get the right duration time ? Which means I have to 6 hrs duration instead of 18 hrs.
댓글 수: 0
채택된 답변
Walter Roberson
2020년 8월 21일
Take the difference as you are now. If the difference exceeds 12 hours, subtract the difference from 24.
Or when you do the conversion to numeric hours and minutes from string object, if the end is less than the first add 24 to the end before taking end minus start.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Earth, Ocean, and Atmospheric Sciences에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!