/    Sign up×
Community /Pin to ProfileBookmark

Computing attendance hours

I upload attendance .xml using php and it saves to database.

I tried this data to upload:
100603 10/1/11 5:35 AM 10/1/11 1:35 PM // this is the exact schedule of employee and its 8 hours per day he time in exactly and timeout exactly also, so no problem in computing because it is 8 hours.
100603 10/2/11 5:25 AM 10/2/11 1:55 PM //in this example data the employee time in early in his schedule and time out late. It should be only 8 hours.
100603 10/3/11 5:40 AM 10/3/11 1:40 PM // in this example data the employee time in is late, so even he also late to timeout there’s no exemption because he late on his work. So it should has deduction or minus in his total hours.

and it saves it database:
100603 2011-10-01 05:35:00 2011-10-01 13:35:00
100603 2011-10-02 05:25:00 2011-10-01 13:55:00
100603 2011-10-02 05:40:00 2011-10-01 13:40:00

I want to accomplish is to get the total hours of the employee based on the employee no. And even the employee get timein early before his time or late to timeout the hours computed only 8 hours. Honestly, I don’t have idea how can be possible it is.

and I tried this code for computing the hours per day:

[code]
select sec_to_time(unix_timestamp(timeout) – unix_timestamp(timein)) AS totalhours from employee;
[/code]

and the result of this code is:

totalhours:
08:00:00
08:30:00
08:00:00

and the result is

the first is correct because the real schedule is 5:35 AM – 1:35 PM
the second is wrong it should be 8 hours only even he timein early and timeout late.
the third is also wrong because the employee is late to timein, even he also timeout late., it should be deduct or subtract in hours the late of employee.

I hope someone can help me. Thank you

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@newphpcoderauthorOct 25.2011 — Good day!

I have new sample for further understanding of my problem.

The real schedule of employee DS-1001 is from 9:35 PM to 5:35 AM he is night shift and the employee DS-1002 is from 5:35 AM to 1:35 PM he is morning shift.

here is the sample .xml file

EMP_NO Time In Time Out

DS-1001 10/1/11 9:35 PM 10/2/11 5:35 AM // this is the exact timein and timeout so theres no problem

DS-1001 10/2/11 9:00 PM 10/3/11 6:00 AM // in this sample the employee timein early and also timeout late.

DS-1001 10/3/11 10:00 PM 10/4/11 5:00 AM // in this sample the employee late to timein and he timeout early, so it should be subtract in his attendance total hours,

DS-1002 10/1/11 5:35 AM 10/1/11 1:35 PM// this is the exact timein and timeout so theres no problem

DS-1002 10/2/11 5:00 AM 10/2/11 2:00 PM// in this sample the employee timein early and also timeout late.

DS-1002 10/3/11 6:00 AM 10/3/11 1:00 PM// in this sample the employee late to timein and he timeout early, so it should be subtract in his attendance total hours,


and the data save in database is:

EMP_NO timein timeout total rendered

DS-1001 2011-10-01 21:35:00 2011-10-02 05:35:00 00:00:00 00:00:00

DS-1001 2011-10-02 21:00:00 2011-10-03 06:00:00 00:00:00 00:00:00

DS-1001 2011-10-03 22:00:00 2011-10-04 05:00:00 00:00:00 00:00:00

DS-1002 2011-10-01 05:35:00 2011-10-01 13:35:00 00:00:00 00:00:00

DS-1002 2011-10-02 05:00:00 2011-10-02 14:00:00 00:00:00 00:00:00

DS-1002 2011-10-03 06:00:00 2011-10-03 13:00:00 00:00:00 00:00:00

OT

00:00:00

00:00:00

00:00:00

00:00:00

00:00:00

00:00:00

EMP_NO datatype is varchar

timein datatype is datetime

timeout datatype is datetime

total datatype is time

rendered datatype is time

OT datatype is time

the total field is the sum of the total hours of the employee

the rendered field is the exact 8 hours of employee or if the employee late like for example he is late or timeout early it should be subtracted and be output in rendered but normally it is 8 hours if his not late. In this field I don't have idea how can i do that.

the OT field is the total - rendered field.

I dont know how can I insert that in my database.



I used this code to get the total hours but it did not work, and no error displayed.

<i>
</i>INSERT INTO employee (total) SELECT sec_to_time(unix_timestamp(timeout) - unix_timestamp(timein));I hope somebody can help me...

Thank you so much...
Copy linkTweet thisAlerts:
@newphpcoderauthorOct 25.2011 — I change my syntax from insert to update because the total field will only update because they are in same table of timein and timeout, so I used this syntax and i test it in mysql:


Code:

UPDATE employee

SET total= sec_to_time(unix_timestamp(timeout) - unix_timestamp(timein));When I used this syntax, the output was add in total field and it is correct...Now my problem is in the rendered, i dont know how can I display the rendered time the 8 hours or below 8 hours if he is late or early to timeout.Because now in total i only used update query and i run it in mysql.

In rendered it only gets the 8 hours from like for example 9:35 PM to 5:35 AM if he timein 9:00 PM he only get from 9:35PM - 5:35 AM or if he timeout 5:40 AM only the 9:35 PM - 5:35 AM he sum and insert in rendered field.

Thank you so much...
×

Success!

Help @newphpcoder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...