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
with an existing funcion it is solveable
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?
Nice question
Solution Comments
Show commentsProblem Recent Solvers2969
Suggested Problems
-
Omit columns averages from a matrix
595 Solvers
-
490 Solvers
-
991 Solvers
-
724 Solvers
-
Find my daddy long leg (No 's')
2481 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!