techiefreak05 Posted January 23, 2008 Share Posted January 23, 2008 The title is the best I could do to describe my problem. I'm making an online Employee Time-Clock application for a client, and I'm getting progress, but I'm sorta stuck with something. When an employee enters their ID and password, it inserts a row into a table called "timePunch" wit the data, " ID - empID - activityID - timeYear - timeDate - timeMonth - timeHour - timeMinute - timeAP" where empID is the ID of the employee. IF there is a row with their empID and activityID="In", then it inserts a row with their empID, and activityID="Out" My question is, how can I calculate how many hours an employee has worked from counting the time from all the rows with their empID? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/ Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 You have 5 columns that can be replaced with 1, unix timestamp. Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-447397 Share on other sites More sharing options...
techiefreak05 Posted January 24, 2008 Author Share Posted January 24, 2008 Yes I originally just had 1 column for the time, using time(), and it would work, BUT I need to allow to administrator to edit each time entry down to the minute. And The only way I knew how to be able to hold 5 areas of time, all of which are editable, is to have 5 separate columns.... Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-447420 Share on other sites More sharing options...
revraz Posted January 24, 2008 Share Posted January 24, 2008 You can edit unix time to the second. Having it like you do makes things harder to work with. Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-447448 Share on other sites More sharing options...
beebum Posted January 24, 2008 Share Posted January 24, 2008 I agree. You should be using unix timestamp, timestamp, or datetime. Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-447514 Share on other sites More sharing options...
GingerRobot Posted January 24, 2008 Share Posted January 24, 2008 Im a little confused. What happens after data has been entered twice? So the first time data is entered, it's listed as activityID as being IN? And the second time, its OUT? Then what? And i'll add the third opinion - a timestamp would be much easier. To edit, you can always make the php script to format the timestamp into a more human readable form. Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-447618 Share on other sites More sharing options...
fenway Posted January 24, 2008 Share Posted January 24, 2008 DATE_FORMAT() is your friend. Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-448000 Share on other sites More sharing options...
techiefreak05 Posted January 24, 2008 Author Share Posted January 24, 2008 It just hit me on how to use date() instead of 5 different columns.. haha ill report back when i get it done. Wait.. I know how to change the value of time() using date, inot a readble format, but how can i take a readable format and turn it into a value like time() Because i will hold the time they punched in wit hthe time() function... but for the admin to edit it, they wil need to edit it in a readable form... Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-448296 Share on other sites More sharing options...
fenway Posted January 24, 2008 Share Posted January 24, 2008 You shouldn't be storing readable format in the db. Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-448365 Share on other sites More sharing options...
techiefreak05 Posted January 24, 2008 Author Share Posted January 24, 2008 I got it. Using the time() value then making it readable by using date(A,$var), etc... and im combining the fields in the form using mktime() to make the unix timestamp. so its working! Quote Link to comment https://forums.phpfreaks.com/topic/87467-solved-how-to-count-emplyee-hours-from-2-rows/#findComment-448381 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.