IN PHP HOW WE CAN SHOW TWO DAYS WORKING HOURS

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
gagan
Forum Newbie
Posts: 10
Joined: Fri Jan 30, 2009 5:03 am

IN PHP HOW WE CAN SHOW TWO DAYS WORKING HOURS

Post by gagan »

HI EVERYONE,

I have one problem, as i calculate two time like today i have worked 9.43 hours and last day i worked 8.20 hours when i calculate total time of these two day then it shows 17.63 hours but i want to show this with the help of php , this should come as like 18.03 hours.

How i can do this , please help me.

regards,
Gagan
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: IN PHP HOW WE CAN SHOW TWO DAYS WORKING HOURS

Post by onion2k »

Convert the two times to minutes, add them, then convert the result back to hours.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: IN PHP HOW WE CAN SHOW TWO DAYS WORKING HOURS

Post by Mark Baker »

You're getting:
9.43
8.20 +
-----
17.63

That is standard mathematics.


To do:
9:43
8:20 +
-----
18:03

You have two choices.
1) You use a PHP date/time stamp for your times, and the date functions to convert input to date/timestanp and reformat it back for display
2) You convert the hours and minutes to a true decimal using hours + minutes/60, and then reverse the process to display the result
Post Reply