Duration between two times - how do you calculate?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Duration between two times - how do you calculate?

Post by simonmlewis »

Code: Select all

echo date("H:i", strtotime($row->timestart)); 
      echo " til ";
      echo date("H:i", strtotime($row->timeend)); 
      
      $v =  strtotime($row->timeend) - strtotime($row->timestart);
      echo " (Duration: ";
      echo date("h", $v);
      echo "hrs ";
      echo date("i", $v);
      echo "mins)";
This is bizarre.
$row->timestart is 19:00:00
$row->timeend is 21:00:00

Yet the result from the above on a LIVE server shows 7 hours.
Result from my local machine shows 3 hours.
If I change the LIVE one to 19:30 timeend, it says 3hrs 30 mins.

How the heck is that possible??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: Duration between two times - how do you calculate?

Post by MindOverBody »

In which format are timestart and timeend variables?
Post Reply