Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.databases.ms-access > #11987

Re: Elapsed Time Between Records

From Ulrich Möller <knobbi38@arcor.de>
Newsgroups comp.databases.ms-access
Subject Re: Elapsed Time Between Records
Date 2016-08-23 12:57 +0200
Organization A noiseless patient Spider
Message-ID <npha72$kfo$1@dont-email.me> (permalink)
References <7gmmrbhcnqv961ogvtv3o7cpgka2toqqqf@4ax.com>

Show all headers | View raw


Am 22.08.2016 um 22:04 schrieb croy:
> I have a table, "tblSurv", that contains a Date/Time field.
>
> I'd like to make a query that sorts by the Date/Time field,
> and creates a calculated field for the number of hours and
> minutes elapsed between each pair of records.
>
> It seems so simple, and yet, I am totally without a
> solution.
>
I guess you want to calculate the difference between the date of the 
current record and the date of the previous record. In that case you can 
use something like this:

SELECT t1.id,

        t1.TIMESTAMP,
        Datediff("d", (SELECT TOP 1 TIMESTAMP
                       FROM   tblsurv AS t2
                       WHERE  t2.TIMESTAMP < t1.TIMESTAMP
                       ORDER  BY TIMESTAMP DESC,
                                 id), t1.[timestamp]) AS Differenz
FROM   tblsurv AS t1;

In this example the subselect addresses the previous record. It should 
be easy to adapt this to your specific problem.

Ulrich

Back to comp.databases.ms-access | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Elapsed Time Between Records croy <croy@invalid.net> - 2016-08-22 13:04 -0700
  Re: Elapsed Time Between Records Patrick Finucane <patrickfinucanetx@gmail.com> - 2016-08-22 13:49 -0700
  Re: Elapsed Time Between Records Ulrich Möller <knobbi38@arcor.de> - 2016-08-23 12:57 +0200
    Re: Elapsed Time Between Records croy <croy@invalid.net> - 2016-08-23 09:59 -0700
      Re: Elapsed Time Between Records Ulrich Möller <knobbi38@arcor.de> - 2016-08-24 14:14 +0200
        Re: Elapsed Time Between Records croy <croy@invalid.net> - 2016-08-24 10:52 -0700
          Re: Elapsed Time Between Records Ulrich Möller <knobbi38@arcor.de> - 2016-08-24 23:38 +0200
  Re: Elapsed Time Between Records Mike P <mikewpayne@tiscali.co.uk> - 2016-08-23 05:36 -0700
    Re: Elapsed Time Between Records croy <croy@invalid.net> - 2016-08-23 09:43 -0700
      Re: Elapsed Time Between Records Mike P <mikewpayne@tiscali.co.uk> - 2016-08-23 10:51 -0700
        Re: Elapsed Time Between Records croy <croy@invalid.net> - 2016-08-23 12:21 -0700
          Re: Elapsed Time Between Records Mike P <mikewpayne@tiscali.co.uk> - 2016-08-24 02:14 -0700
        Re: Elapsed Time Between Records Ulrich Möller <knobbi38@arcor.de> - 2016-08-24 11:25 +0200

csiph-web