Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Suggestions for timeclock program

Status
Not open for further replies.

chris86t

Technical User
Jun 13, 2008
41
US
I am making a timeclock program to keep track of hours worked. I'm trying to figure out the best way to calculate the hours worked in a week.

Here is the mysql table where the information is stored:
Code:
+----+---------------------+--------+---------+------------+
| id | date_time           | in_out | users   | weekofyear |
+----+---------------------+--------+---------+------------+
| 34 | 2009-12-04 20:26:04 |      1 | mdowers |         49 |
| 35 | 2009-12-04 20:26:15 |      0 | mdowers |         49 |
| 36 | 2009-12-04 20:31:31 |      1 | mdowers |         49 |
| 37 | 2009-12-04 20:31:57 |      0 | mdowers |         49 |
+----+---------------------+--------+---------+------------+
This data is tied into a datagridview. I just can't come up with the best way to add up the hours in the week.
 

If mdowers started at 2009-12-04 20:26:04 and was done at 2009-12-04 20:26:15 - he/she was at work for 11 seconds (do the time diff between those 2 dates), plus: 2009-12-04 20:31:57 minus 2009-12-04 20:31:31 it is only 26 seconds.

Not very busy bee.... :)

Have fun.

---- Andy
 
Here's what I came up with.

Ask for input for week to calculate
Send select statement to database to get data for that week.
Loop through the dataset and calculate the hours worked by adding:
Code:
(out_time_hours - in_time_hours)+(out_time_mins - in_time_mins) / 60
(i'm not worried about seconds.)

Right now i have this working for one instance of in and out. Now I just need to make it work for the whole week of punches.

[smile]mdowers is my wife, which explains the amount of time worked[smile]
 
The program is working great now except for one thing. When clocking in on one day and clocking out on the following day, the hours calculated are incorrect. I think adding 24 to the hours of the clocked out time should fix it. Any suggestions?
 
Adding 24 works ok, but I'm just going to use epoch instead. It simplifies the code so much.
 

Just use the DateDiff function to get the number of minutes between clock in time and clock out time:

Dim MinutesWorked As Double
Dim HoursWorked As Double

MinutesWorked = DateDiff(DateInterval.Minute, StartDateTime, EndingDateTime)

HoursWorked = MinutesWorked / 60


This way you don't have to worry about someone clocking in on one day and clocking out on the following day.


I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top