Jump to content

calendar dates


synstealth

Recommended Posts

user submits the hours they worked in db. there will be more than 5 rows of hours they submitted.

I want to pull the rows of hours they submitted and add them up all to find out how many hours they have worked.

 

 

 

the values will be in 0:00 format.

 

how do I do calculation part

(I know how to connect,pull records and get the times but i dont know how to add them up and total it in time format)

help would be appreicated

 

 

 

 

Link to comment
Share on other sites

pull them in UNIX_TIMESTAMP

 

ex:

 

mysql_query(SELECT UNIX_TIMESTAMP(time_1) FROM work_hours)

 

add the time stamps together and then convert back to hours

 

for example user submits hours,

 

hours are inserted using default date,

 

pull hours in time stamp, subtract time stamp for default date with 0 hours

 

a unix time stamp is recorded in seconds so converting back to hours is just a matter of multiplying by 60 a couple times

 

check the php manual for mktime for more examples

Link to comment
Share on other sites

I think it would be much easier to store the worked time in decimal format. That way you can use the MySQL SUM function to get total time worked. Just create functions to convert from decimal to time format and vice versa.

 

Unless I am mistaken the SUM() function does not work on time fields in MySQL - at least a quick test I did didn't seem to generate the results I expected.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.