Time calculation between 2 dates |
Hi Friends,
I have 2 dates with time as below: From: 2017-03-09 09:26:00 To: 2017-03-11 09:25:00 I need to calculate exact Hour and minutes difference between 2 dates.. However I could get only 23:00 for diff functions. I need the exact hours and minutes difference.. Please help
Perhaps not the most elegant - but it works.
PHP Code:
@Dave friend solution can be slightly simplify
PHP Code: $start = new DateTime("2017-03-09 09:26:00"); A good decision is based on knowledge and not on numbers. - Plato
(03-31-2017, 12:14 AM)salain Wrote: @Dave friend solution can be slightly simplify @salain, But that won't give the right answer if the interval is more than a day. Those hours must me added to the result.
(03-31-2017, 06:10 AM)salain Wrote: @Dave friend you are right, but your option would also be wrong if it is more than a month. An excellent point! This revised code handles that. PHP Code: $start = new DateTime("2017-03-09 09:26:00"); |
Welcome Guest, Not a member yet? Register Sign In |