473,387 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to find working hours

9
how can i find total working hours for an employee by calculating his check in and check out time?
Suppose if employee work for 2 hrs and check out for some reason and again check in then how to find total working hours. In database time is given in datetime format. thanks in advance.
Jan 19 '12 #1
11 4550
C CSR
144 100+
Where are you going to make your calculations? What language?
Jan 19 '12 #2
ssoni
9
Have to create a stored procedure for it in sql server 2008.
Jan 20 '12 #3
C CSR
144 100+
When they clock out, does it do any totally of the hours for that period already? Or, do you have it set up to just input the PunchinTime and the PunchoutTime, and want to do the totally per period at some point later, like weekly, biweekly, etc. A good app would handle the totaling in realtime. Example (hope it fits):

EmpID Date Punchin Punchout PeriodTotalHrs
1 1/20/2012 10:32:00PM NULL NULL
1/20/2012 10:32:00PM 04:25:00 AM [calculated now]

(note this is the same record, edited on Punchout)

Then you would just be totaling the PeriodTotalHrs column at the point of "delivery" (a later time).

If you don't have an app set up to do something like this already, and you have records in there with Punchin/Punchout times but nothing in the PeriodTotalHrs column (or it doesn't exist), then we have 2 types of calculations to do. Do you need both?
Jan 20 '12 #4
C CSR
144 100+
Sorry, That "table" above didn't format very well.

Expand|Select|Wrap|Line Numbers
  1. EmpID Date      Punchin    Punchout   PeriodTotalHrs
  2. 1     1/20/2012 10:32:00PM NULL       NULL
  3.       1/20/2012 10:32:00PM 04:25:00AM [calculated now]
  4.  
Jan 20 '12 #5
ssoni
9
I have one table in which total hrs of employee is mentioned. like first check in and last check out. and another table is there in which every check in and out are mentioned. now i want to exclude those hrs in which employee is out.
thanks.
Jan 20 '12 #6
C CSR
144 100+
I need to make sure what you're telling me. You said:

A) "one table in which total hrs of employee is mentioned. like first check in and last check out." Does it look like this?

Expand|Select|Wrap|Line Numbers
  1. Tbl1 '            
  2.     Checkin    Checkout    Total hrs
  3. Day 1    [time1]    [time out    8
  4. Day 2    [time1]    [time out    6.5
  5. Day 3    [time1]    [time out    7
  6.  
Then you said:

B) "another table is there in which every check in and out are mentioned." Does it look like this?

Expand|Select|Wrap|Line Numbers
  1. Tbl2            
  2.     Checkin    Checkout    
  3. Day 1    [time1]    [time out]    
  4. Day 2    [time1]    [time out]    
  5. Day 3    [time1]    [time out]    
  6.  
Then you said:

C) "i want to exclude those hrs in which employee is out."

'---------
What do you mean by "exclude" hours when "employee is out"? That part doesn't make since to me.

Please take each piece of your reply as I have above and explain like this:

A) answer:
B) answer:
C) answer:

Be very clear because the coding solution can be different depending on the structure of the information as it appears in the table(s).

Sorry for the delay in my response.
Jan 21 '12 #7
ssoni
9
Hey thnx for ur work..you are nearly close to what i want to explain.

A) First table looks like your table.

B) 1. Tbl2
2. Checkin Checkout Empid
3. Day 1 9:00 11:35 1
4. 12:00 13:05 1
5. 13:40 18:00 1

Now I need to calculate the working hours of employee for which he was in to the office.

Is that possible?

Thanks
Jan 23 '12 #8
C CSR
144 100+
Okay. I assume the data is already in a "Time format" and that you want the result in "decimal" format to be used for other calculations: from the result = 08:00:00 to the result = 8.00 hours. Date/Time calculations automatically does a conversion to the type "double" and the result is given in a ratio that can be converted from seconds to minutes or hours.

For good measure you need a date field (e.g.; 1/20/2012) to make sure you can calculate a time difference if someone checks in late at night on one day and checks out early the next morning (e.g.; 11:00 PM to 1:00 AM). The date and the times have to be in the same value. Then you would have: checkin "1/20/2012 06:00:00 PM" and checkout "1/22/2012 02:00:00 AM." The time calculations will see the date crossover because of its conversion to the "double type."

The calculation follows this order:

Expand|Select|Wrap|Line Numbers
  1. 1)Subtract the Date/Times:  Result is a Date/Time type.
  2.  
  3. 2) Convert to Double type (0.00000000) 
  4.  
  5. 3) Multiply the result * 86400 (to get seconds) and divide by 60 (to get minutes) and divide by 60 again (to get  hours).
  6.  
  7. 4) "Round" to the precision desired (2 or maybe 3) to get  for example, 8.25 hours.
  8.  
There are built in time functions for various programming languages that you could use but I have to know what it is if you want to work the calculations outside of the SQL server.

Here are 2 Update queries that should work in SQL server. One only uses a conversion to double, the other uses a function called DateDiff to make the conversion and shorten the math.

The inside calculation is:

CDbl([Hours]![checkout]-[Hours]![checkIn])*86400/60/60,

then I Round it so the final looks like this (note the precision 2 on the end):

Round(CDbl([Hours]![checkout]-[Hours]![checkIn])*86400/60/60,2)

Expand|Select|Wrap|Line Numbers
  1. UPDATE Hours SET Timeclock.TotHours = Round(CDbl([Hours]![checkout] - [Hours]![checkin]) * 86400/60/60, 2)
  2. WHERE (((Hours.EmpID)="100"));
  3.  
You might also be able to use: Round(DateDiff("n",[Hours]![checkIn],[Hours]![PunchOut]) /60,2), where the "DateDiff" function take away the seconds and minutes calculations.

Expand|Select|Wrap|Line Numbers
  1. UPDATE Hours SET Timeclock.TotHours = Round(DateDiff("n",[Hours]![checkIn],[Hours]![checkOut])/60,2)
  2. WHERE (((Hours.EmpID)="100"));
  3.  
Are there any complications I'm unaware of?
Jan 23 '12 #9
C CSR
144 100+
Also, these queries assume you have a Field called "ToTHours" (for each checkin/checkout record)in the same table to capture the Result. Once those columns are filled you can total them in a query based on the EmpID. I don't know where you want that total to end up (another table?) and I don't know when you will run the query as part of your program, so I didn't include it in my answer.
Jan 23 '12 #10
C CSR
144 100+
To avoid confusion, I typed in "Timeclock" as the tablename, but it should have said "Hours.TotHours" to correspond with the other fields, like "[Hours]![checkin] and [Hours!checkout], etc. Sorry for my sloppy work :(
Jan 23 '12 #11
For more information u click below links:

none Time Clock Table Design - Revisited - MSDN - MicrosoftSolving

Complex T-SQL Problems, Step-By-Step - Simple Talk
Dec 9 '13 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nikolai Onken | last post by:
Hey, I got a rather more mathematical Problem but have no idea how to solve it: I have following values and want them to return other values as stated below: (Best seen with fixed pitch font)...
0
by: Rahmi Acar | last post by:
Can any one redirect me to the place where i can find the stuff i need? Im by the way adding net time protocol so it will syncronise by it's own intergated watch. This is a start stopp application...
14
by: niknokio | last post by:
Hi I need to be able to calculate the working time between a StartDate and an EndDate. the data is in dd/mm/yyyy hh:mm:ss format and given an 8.5 hr day (weekdays). Ive found lots of really...
1
by: deena22 | last post by:
hello, i'm using 'Access database' and VB 6.0. My database is named ' timesheet' and it contains a table named 'tabletimesheet'. The table contain the following fields: 'staffname, stafftype,...
3
by: Dan | last post by:
I'm trying to calculate the total work hours between a start and end date, and also working out an end date by adding a number of work hours to a start date. Can anyone recommend a decent formula...
9
by: mgrubbs | last post by:
#include <iostream> using std::cout; using std::cin; using std::endl; int main() { int code = 0; int charges = 0;
10
bsmeena7005
by: bsmeena7005 | last post by:
Hi help me to calculate the working hours between 10 to 18 hrs between two dates including the weekends also no braek or lunch time Example :- start date #01-08-2009 08:45:23# end date ...
10
by: LSGKelly | last post by:
I have some code in my database that calculates time between two date/time fields and also calculates the weekends and holidays. I did not create this code, so I'm at a bit of a loss why it's not...
1
Sl1ver
by: Sl1ver | last post by:
Hi my problem currently is that i need to get database on working hours(7am-5pm) so lets say a order lies in the database for e.g 4 days if i just get like timediff i will end up 96 hours...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.