Time card formula

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
sethkain
Forum Newbie
Posts: 2
Joined: Mon Nov 10, 2003 4:24 pm
Location: Gadsden, Alabama
Contact:

Time card formula

Post by sethkain »

:arrow:
i am kind of new to php, and i am trying to write a timecard app. but i am having a problem trying to come up with the formula that calculates how many hours an employee has worked. the table in the db contains
timeid :: unique id
coid :: company id
employeeid :: employee id
date :: the date
time :: the time
action :: either in or out
employees can clock in or out multiple times durning the day. i just need to figure out how to calculate the total time an employee has been working.
thanks
:arrow:
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

I'd suggest reading:
http://www.mysql.com/doc/en/Date_and_ti ... tions.html

As you have the time (both in and out) you should be able to easely calculate the difference using one of the many functions directly in MySQL by using either DATEDIFF(expr,expr2) or TIMEDIFF(expr,expr2).

Hope I gave some good ideas.
sethkain
Forum Newbie
Posts: 2
Joined: Mon Nov 10, 2003 4:24 pm
Location: Gadsden, Alabama
Contact:

Post by sethkain »

I have been trying all day to make TIMEDIFF make sense to me in my situation. first i am confused on how to exactly make it work in my script. How do i get EXPR1 and EXPR2 for it to subtract?
my tctime table is setup like this
:arrow:
timeid coid employid date time action
53 100 1 2003-11-10 11:29:36 in
54 100 1 2003-11-10 11:36:12 out
55 100 1 2003-11-10 11:40:54 in
56 100 1 2003-11-10 11:55:25 out
i am pulling all the information out of the db like this
:arrow:
$today=date('Y-m-j');
$sql = "select * from tctime where coid='$coid' and employid='$employid' and date='$today' order by time asc";
$sql_result = mysql_query($sql,$connection) or die (mysql_error());
now how do i get TIMEDIFF to show how much time employee 1 has worked?
thanks for all of your help and time it is very much appreciated.
Post Reply