Results 1 to 5 of 5

Thread: Totalling Hours

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Totalling Hours

    Hello,
    I have a report that calculates the salaries of employees. In addition to that it calculates overtime hours. Now, I've been trying to work on a formula that would calculate the number of overtime hours. Which is supposed to be if an employee stayed for more than 8 hours at work. It would calculate the rest of the time as overtime. So let's say if an employee worked for 11 hours it would put in the field 3. Any ideas?

  2. #2
    Fanatic Member Dnereb's Avatar
    Join Date
    Aug 2005
    Location
    Netherlands
    Posts
    863

    Re: Totalling Hours

    did you look at DateDiff you can add all working time with this function in minutes ("n"), subtract the amount of minutes that aren't overtime.
    if the result is positive you've got overtime if it's negative to employee has taken some free time.
    why can't programmers keep and 31 Oct and 25 dec apart. Why Rating is Useful
    for every question you ask provide an answer on another thread.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Re: Totalling Hours

    Well, actually, it's a little complicated than that. Because the employee can punchin and punchout twice on the same day. So perhaps what I was looking for is the sum of DateDiff per day and then calculate if it's over 8 hours then there is over time else there is no over time. If someone can give me a forumla it would really be appreciated. Thanx.

  4. #4
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Totalling Hours

    Don't know why you cannot read the help files and experiment then post up that experiment...?

    Perhaps something like:
    Code:
    Select 
     TheDateF, 
     sqryDiffs.TheTimeDiff as TotalHoursDay, 
     iif((sqryDiffs.TheTimeDiff * 24)>8,(sqryDiffs.TheTimeDiff * 24)-8,0) as OverTime
    From
     (select table.employeeid, format(table.thedate,'dd mmm yyyy') as TheDateF, sum(table.clockout-table.clockin) as TheTimeDiff
      From table
      Group By table.employeeid, format(table.thedate,'dd mmm yyyy')
     ) as sqryDiffs
    The sub query gets each difference from clockin to clockout and sums them together, grouped by the employeeid and the date the record applies too (thedate).
    The main query theen uses the total and works out if it is greater than 8 to subtract 8 to give the over time done.
    Now the only possible problem is that the differences would be in fractions of a day (1 being 24 hrs) so I have added that in as well.
    Try it and see if it works. If not perhaps you can change it to work correctly, or use it as a base to build a different solution.

    good luck

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cairo, Egypt
    Posts
    275

    Re: Totalling Hours

    So, I would make an SQL expression field, paste the following in it, right?
    But what should substitute thedateF for?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width