Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

All About Time...

Status
Not open for further replies.

slurpyx

Programmer
Aug 1, 2002
59
PH
Am trying to create a simple program that will compute for an employees time in and time out. I just want to know how to compute for the difference of a time in and time out, even if an employee time in 8.00am jan 7 and time out jan 9 8.00am. we get that a lot from here. i just want to compute the time difference or the total time consumed within a time in and time out...

I tried this:
$sec = mktime(10,0,0,1,9,2004) - mktime(8,0,0,1,9,2004);
echo date('H:i:s', $sec); // will echo 18:00:00

How can i convert this into real time? as in total hours and minutes like, i want the above example to produce "2:00".

how can i do this?
 
I know that this:

$dateDiff = mktime(12,20,0,04,20,2003) - mktime(11,0,0,04,20,2003);
echo 'Difference in seconds: ' . $dateDiff . '<br />';

echo '<br />Years Difference = '. floor($dateDiff/365/60/60/24);
echo '<br />Months Difference = '. floor($dateDiff/60/60/24/7/4);
echo '<br />Weeks Difference = '. floor($dateDiff/60/60/24/7);
echo '<br />Days Difference = '. floor($dateDiff/60/60/24);
echo '<br />Hours Difference = '. floor($dateDiff/60/60);
echo '<br />Minutes Difference = '. floor($dateDiff/60);

will produce something like:

Difference in seconds: 4800

Years Difference = 0
Months Difference = 0
Weeks Difference = 0
Days Difference = 0
Hours Difference = 1
Minutes Difference = 80

But i want to get the 1:20 hours:mins output? how do i do this?
 
You did all the computations you need. All that is left is to assemble the hours and remainder of minutes [modulus 60]:
Code:
echo('<br />Hours and minutes = '. floor($dateDiff/60/60).':'.(floor($dateDiff/60)%60));
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top