Results 1 to 4 of 4
  1. #1
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76

    Time Card Query Issue (dateDiff)

    I have a time card application with an issue. If someone clocks in and then clocks out, the below executes as expected. The issue is if they clock in and out multiple times during the same day and the total amount worked is greater then 8 hours no overtime is granted. How can I group TotalTime by the same day?

    TotalTime: DateDiff("n",[StartTime],[FinishTime])
    overtimeMin: IIf([TotalTime]>480,[TotalTime]-480)
    OverTimeHours: [overtimeMin]\60 & Format([overTimeMin] Mod 60,"\:00")


    TotalMinLessOvertime: IIf([TotalTime]>480,480,[TotalTime])


    Thanks,

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,921
    Maybe calc the date part of the StartTime value and do aggregate query that groups on that.

    Complication arises if workday crosses midnight.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Rawb is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    The best way to handle this is to store three pieces of information for each record:
    ClockInDate: This is the date the user clocked in on. This should be stored separately so that later on, you can use this field in a GROUP BY clause. Formatted as a Short Date.
    StartTime: This is the date and time the user clocked in. Formatted as a General Date.
    FinishTime: This is the date and time the user clocked out. Formatted as a General Date.

    Then, to get your minutes worked, change your Query to Totals and use the following calculated fields:
    Code:
    TotalTime: Sum(DateDiff("n",[StartTime],[FinishTime]))
    overtimeMin: IIf(Sum(DateDiff("n",[StartTime],[FinishTime]))>480,Sum(DateDiff("n",[StartTime],[FinishTime]))-480, 0)
    OverTimeHours: Format(Int(IIf(Sum(DateDiff("n",[StartTime],[FinishTime]))>480,Sum(DateDiff("n",[StartTime],[FinishTime]))-480, 0)/60), "00") & Format(IIf(Sum(DateDiff("n",[StartTime],[FinishTime]))>480,Sum(DateDiff("n",[StartTime],[FinishTime]))-480, 0) Mod 60,"\:00")
    TotalMinLessOvertime: Sum(DateDiff("n",[StartTime],[FinishTime]))-IIf(Sum(DateDiff("n",[StartTime],[FinishTime]))>480,Sum(DateDiff("n",[StartTime],[FinishTime]))-480,0)
    For all 4 of these fields, you will need to change the Totals column from "Group By" to "Expression".

    I know the OverTimeHours field is particularly ugly, but that's a byproduct of using a Totals Query - You can no longer just use the alias, you have to re-enter the whole formula.

    Check out the attached DB for an example.
    Attached Files Attached Files

  4. #4
    ShostyFan is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    76
    thank you so much for the time you put into this. I was able to get everything working exactly the way I wanted it to.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 07-09-2014, 07:13 AM
  2. datediff in query
    By xeon_tsd in forum Programming
    Replies: 6
    Last Post: 04-08-2014, 01:40 AM
  3. Calculate DateDiff on Time Added Field
    By athyeh in forum Queries
    Replies: 9
    Last Post: 12-18-2013, 02:10 PM
  4. Issue with time query
    By Reynardine in forum Queries
    Replies: 2
    Last Post: 09-23-2012, 08:49 AM
  5. Criteria from form to query with wild card
    By SteveW in forum Queries
    Replies: 3
    Last Post: 04-01-2011, 07:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums