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 Solvers2972
Suggested Problems
-
Project Euler: Problem 7, Nth prime
1569 Solvers
-
Rotate and display numbered tile
358 Solvers
-
Remove the two elements next to NaN value
659 Solvers
-
741 Solvers
-
Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)
776 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!