synstealth Posted February 26, 2008 Share Posted February 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/93132-calendar-dates/ Share on other sites More sharing options...
amites Posted February 26, 2008 Share Posted February 26, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/93132-calendar-dates/#findComment-477196 Share on other sites More sharing options...
Psycho Posted February 26, 2008 Share Posted February 26, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/93132-calendar-dates/#findComment-477218 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.