Problem 62. Elapsed Time
Given two date strings d1 and d2 of the form yyyy/mm/dd HH:MM:SS (assume hours HH is in 24 hour mode), determine how much time, in decimal hours, separates them. Assume d2 is always later than d1.
Example:
Input d1 = '2010/12/14 12:00:00' Input d2 = '2010/12/14 13:06:36' Output elapsed is 1.11
Solution Stats
Problem Comments
-
12 Comments
Show
9 older comments
Laza Álmos
on 27 Mar 2020
with an existing funcion it is solveable
Bugrahan Atar
on 9 Feb 2021
function elapsed= elapsed_time(d1,d2)
d1='2010/12/14 12:00:00'
d2='2010/12/15 13:06:36'
a=(str2num(d2(1:4))-str2num(d1(1:4)))*8760;
b=(str2num(d2(6:7))-str2num(d1(6:7)))*720;
c=(str2num(d2(9:10))-str2num(d1(9:10)))*24;
e=str2num(d2(12:13))-str2num(d1(12:13));
f=(str2num(d2(15:16))-str2num(d1(15:16)))/60;
g=(str2num(d2(18:19))-str2num(d1(18:19)))/3600;
elapsed=a+b+c+e+f+g
end
it told me that solution is wrong?
Tân Trần
on 7 Jul 2021
Nice question
Solution Comments
Show commentsProblem Recent Solvers2966
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!