Results 1 to 3 of 3
  1. #1
    GMACDEE is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    Mar 2016
    Posts
    1

    Subtracting time between dates in two different records

    I would like to be able to subtract time between to records and from two different fields. I have three fields in a query, Equipment ID, Start Time & End Time are the fields. I would like to subtract the time between the first End Time and the next Start Time. This would have to be against the Equipment ID. Thanks for any help.


    Example
    Equipmnet Desription Start Time End Time Time Diff
    Machine #1 14/2/2007 9:00 AM 14/2/2007 9:30 AM
    Machine #1 20/2/2007 8:45 AM 20/2/2007 9:30 AM 143:15:00
    Machine #1 19/3/2007 7:45 AM 19/3/2007 8:30 AM 646:15:00
    Machine #1 6/2/2008 9:00 AM 6/2/2008 11:30 AM 7776:30:00

  2. #2
    NoellaG's Avatar
    NoellaG is offline VIP
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Jun 2010
    Location
    Belgium
    Posts
    1,180
    Hi,

    with the function datediff you can calculate the interval between two dates. If you choose 's' as interval you get the number of seconds between datetime1 and datetime2: for example = datediff"s", endtime, begintime)

  3. #3
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    the time format is limited to 24 hours, so you will need to find a way of displaying as you require (your last record will not display correctly since it is greater than 1440 minutes) - there are plenty of examples how to do this - no time to find one myself, so google it. But with regards your basic query

    Code:
    SELECT *, starttime-(SELECT Max(endtime) from myTable as T where Equipment=myTable.equipment and endtime<=myTable.starttime) as downtime
    FROM myTable
    ORDER BY StartTime

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

Similar Threads

  1. vba > subtracting time
    By metokushika in forum Access
    Replies: 2
    Last Post: 12-09-2014, 09:17 PM
  2. #ERROR when subtracting dates
    By nlkehl in forum Queries
    Replies: 7
    Last Post: 08-26-2014, 08:24 AM
  3. Adding and subtracting dates from current date
    By brianmcleer in forum Access
    Replies: 1
    Last Post: 05-07-2013, 05:15 PM
  4. Subtracting Dates in Queries
    By seanpbent in forum Access
    Replies: 1
    Last Post: 02-01-2013, 04:28 PM
  5. adding and subtracting two time
    By smahdih in forum Queries
    Replies: 3
    Last Post: 11-20-2011, 03:21 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