Results 1 to 10 of 10
  1. #1
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17

    time between shifts

    I'm trying to calculate the time between when one shift ends and the next begins.
    My table is set up so each shift has it's own row/ID.

    My issue is that the data I need are on different lines and I'm not sure how to do this query in Access. I could easily do it in Excel but I need the info in this database.

    Any suggestions?

    Thanks!

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    You will need a DateDiff Function. Example:
    GrandTotal: DateDiff("n",[StartTime],[EndTime])/60

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,644
    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.

  4. #4
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17
    Quote Originally Posted by June7 View Post
    I have the datediff function but I can't seem to figure out this subquery
    This is the query I have now using the datediff function (in Time1 query).
    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	5.7 KB 
ID:	18577
    I need the subquery to take id 4 power_on - id 2 end_pour.

    I don't know how to insert my info into that code from the link you gave me.

  5. #5
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Okay, here again is an Example: Duration is a calculated expression.

    Place this function in a standard module. If you create a new module to do this, name the module anything except ElapsedTime.

    Code:
    Public Function ElapsedTime(Start As Date, Finish As Date) As String
    'Calculates elapsed time between 2 date/times and
    'parses it out into Hours-Minutes-Seconds in HH:MM:SS format
    Dim HoursLapsed, SecondsLeft, MinutesLapsed, SecondsLapsed As Long

    TotalSeconds = DateDiff("s", Start, Finish)

    HoursLapsed = Int(TotalSeconds / 3600)

    SecondsLeft = TotalSeconds Mod 3600

    MinutesLapsed = Int(SecondsLeft / 60)

    SecondsLapsed = SecondsLeft Mod 60

    ElapsedTime = Format(HoursLapsed, "00") & ":" & Format(MinutesLapsed, "00") & ":" & Format(SecondsLapsed, "00")


    End Function
    Now, in the Query Grid for your query, create a new, calculated field like this:

    Duration: ElapsedTime([power_on],[end_pour])
    HTH

  6. #6
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17
    Quote Originally Posted by burrina View Post
    Okay, here again is an Example: Duration is a calculated expression.


    HTH
    I understand the duration calculation but that would calculate the time btw the beginning of the shift to the end of the shift. I need to calculate the time btw shifts (ie: when one shift ends to when the next begins).

  7. #7
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    If you have one query to get the time difference between the 2 start and end times, then you add that query to a new query as has been suggested and then calculate the difference between the start time and the already calculated difference.
    Example:
    ShiftDiff: DateDiff("n",[EmployeeTime],[StartTime])/60
    Where EmployeeTime is from the 1st query to calculate the difference between the 2 times.

    HTH

  8. #8
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17
    Quote Originally Posted by burrina View Post
    If you have one query to get the time difference between the 2 start and end times, then you add that query to a new query as has been suggested and then calculate the difference between the start time and the already calculated difference.
    Example:
    Where EmployeeTime is from the 1st query to calculate the difference between the 2 times.

    HTH
    I already have the DateDiff Function. I know how long it takes btw the beginning of the shift to the end.

    Click image for larger version. 

Name:	Capture.PNG 
Views:	14 
Size:	3.4 KB 
ID:	18583

    Subtracting these isn't going to help me. I need to be able to pull the end_pour from the 1st id and the power_on from the 2nd id

  9. #9
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17
    This is the code I'm using to try and pull the power_on date to the same line as the end_pour date.

    SELECT Time1.ID, Time1.End_Pour,
    (select dupe.power_on from time1 as dupe where dupe.id=time.id+1 orderby dupe.id) as next_power_on
    FROM Time1;

    It's saying I have a syntax error in the 2nd select query

  10. #10
    sarsmelt is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Aug 2014
    Posts
    17
    I figured it out

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

Similar Threads

  1. How to code base on days and hours of shifts
    By boywonder381 in forum Programming
    Replies: 6
    Last Post: 09-23-2014, 01:54 PM
  2. Replies: 6
    Last Post: 05-01-2013, 06:37 AM
  3. Replies: 42
    Last Post: 03-01-2013, 06:58 AM
  4. Formula for counting shifts
    By Huddle in forum Access
    Replies: 4
    Last Post: 05-10-2012, 02:56 PM
  5. Replies: 1
    Last Post: 02-28-2012, 09:16 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