calculate the differnance between 2 time

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

Locked
mahesh_php
Forum Newbie
Posts: 1
Joined: Mon Feb 23, 2009 11:10 pm

calculate the differnance between 2 time

Post by mahesh_php »

Code: Select all

$diff_time=strtotime($time1)-strtotime($time2);
//$diff_time send time in seconds
echo $diff_time;
:roll:
Last edited by Benjamin on Tue May 26, 2009 10:43 am, edited 2 times in total.
Reason: Added [code=php] tags.
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: calculate the differnance between 2 time

Post by Darhazer »

well, avoid using strtotime if it's not completely necessesary.

What's the problem here? You have the difference in seconds...

Code: Select all

 
$resullt = $result / 60; // in minutes
$result = $result / 60; // the above result, in hours
$result = $result / 24; // in days
Maybe you need a function, that outputs '1 Day, 12 hours, 12 minutes and 3 seconds' for example?
Last edited by Benjamin on Tue May 26, 2009 10:42 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: calculate the differnance between 2 time

Post by Benjamin »

Locked due to lack of effort from the op.
Locked