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
The testsuite input does not following the input format string.
Having a hard time with the test suite regarding the number of hours in one year. I think it should be 8 765.81277h/y
The test suite doesnt follow. it should be double digit days and month, not single digits according to his descrption
having problems with the test suite especially test no 3
having problems with test no 3 of the test suite,why?
It's a fun problem
the test suits are all passed , but the mathworks net tells its wrong.
and the size is '-1'.
i use the datenum function.
I use format bank to get 2 decimal output, anyone has a better idea?
using existing functions makes this trick easy
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 Solvers2931
Suggested Problems
-
given 3 sides, find area of this triangle
798 Solvers
-
Are all the three given point in the same line?
429 Solvers
-
547 Solvers
-
5066 Solvers
-
Pernicious Anniversary Problem
821 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!