472,779 Members | 1,816 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,779 software developers and data experts.

Table contains date/time field, I want to query it displaying time-diff between successive records entered. How?

MLH
I have a database (datatrek.mdb) with a table named DATA.
The table has a date/time field [DatumTimeStamp] with default
value = Now(). It has 100 records in it entered over a 50-minute
period.

I would like the query to display 100 records with a new, calculated
field showing timelapse between time of record entry of current record
and time of entry of previous record. For the first record in the
dynaset, I'll settle for a value = 30 seconds. For the last 99 records
in the dynaset, I want to see the ACTUAL time-diffs between the
current and prior record.

Can I make a query do that somehow?
Nov 13 '05 #1
9 2804
MLH
For what its worth, I am hoping that a query can be created
to do what I've described in order to avoid an additional data
field in the table to house the absolute timelapse data.
Nov 13 '05 #2
MLH wrote:
I have a database (datatrek.mdb) with a table named DATA.
The table has a date/time field [DatumTimeStamp] with default
value = Now(). It has 100 records in it entered over a 50-minute
period.

I would like the query to display 100 records with a new, calculated
field showing timelapse between time of record entry of current record
and time of entry of previous record. For the first record in the
dynaset, I'll settle for a value = 30 seconds. For the last 99 records
in the dynaset, I want to see the ACTUAL time-diffs between the
current and prior record.


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Perhaps:

SELECT DatumTimeStamp,
DateDiff("s", (SELECT Max(DatumTimeStamp)
FROM [Data]
WHERE DatumTimeStamp < t.DatumTimeStamp),
DatumTimeStamp) As SecondsTimeLapse

FROM [Data] As t

You could also use the DMax() function instead of the subquery.

See the Access Help articles on DateDiff() and DMax() for more info.

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBQjONx4echKqOuFEgEQKMBQCg9ouDLbjDIhcoH2CAqwAS6E VYfgoAoL7U
QkLQpxT3afDjQ44W/S/vxaKn
=RGfs
-----END PGP SIGNATURE-----
Nov 13 '05 #3
MLH
Hey! That worked! How in the heck did you do that, man?
You're a genius!
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Perhaps:

SELECT DatumTimeStamp,
DateDiff("s", (SELECT Max(DatumTimeStamp)
FROM [Data]
WHERE DatumTimeStamp < t.DatumTimeStamp),
DatumTimeStamp) As SecondsTimeLapse

FROM [Data] As t

You could also use the DMax() function instead of the subquery.

See the Access Help articles on DateDiff() and DMax() for more info.


Nov 13 '05 #4
MLH wrote:
Hey! That worked! How in the heck did you do that, man?
You're a genius!


I'd like to take credit for it, but I devised it based on info in a
Query Examples db provided by Microsoft.

http://www.microsoft.com/downloads/d...displaylang=en

--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #5
MLH <CR**@NorthState.net> wrote in message news:<ak********************************@4ax.com>. ..
I have a database (datatrek.mdb) with a table named DATA.
The table has a date/time field [DatumTimeStamp] with default
value = Now(). It has 100 records in it entered over a 50-minute
period.

I would like the query to display 100 records with a new, calculated
field showing timelapse between time of record entry of current record
and time of entry of previous record. For the first record in the
dynaset, I'll settle for a value = 30 seconds. For the last 99 records
in the dynaset, I want to see the ACTUAL time-diffs between the
current and prior record.

Can I make a query do that somehow?


This can be done. Depends on what you consider the "previous" record.
You can use a subquery such as the following if you're comparing based
on date.

SELECT *, DateDiff("s", (SELECT TOP 1 DatumTimeStamp FROM DATA WHERE
DatumTimeStamp < D.DatumTimeStamp ORDER BY DatumTimeStamp ASC),
D.DatumTimeStamp)
FROM DATA AS D

If you want to compare based on ID values, just change the inner WHERE
clause to compare the IDs using the same idea.\

HTH,
Russell Sinclair
Nov 13 '05 #6
MLH
Could the SQL be taken one step further to never show more than 60
in the [SecondsTimeLapse] field of the query? In other words, any
value greater than 60 calculated by the DateDiff expression would be
shown simply as 60. Wanna take a stab at that?
Nov 13 '05 #7
MLH
Well, I tried this. It worked. I'm happy.

SELECT t.DatumTimeStamp AS Expr1, IIf(DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])>60,60,DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])) AS SecondsTimeLapse
FROM tblDataTESTING AS t;

Nov 13 '05 #8
MLH
In the final analysis, this gave me PRECISELY what I needed...

SELECT t.DatumTimeStamp AS Expr1, IIf(DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])>60 or IsNull(DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])),60,DateDiff("s",(SELECT
Max(DatumTimeStamp)
FROM [tblDataTESTING]
WHERE DatumTimeStamp <
t.DatumTimeStamp),[DatumTimeStamp])) AS SecondsTimeLapse
FROM tblDataTESTING AS t;

Thx again, Mr Foster.
Nov 13 '05 #9
MLH wrote:
In the final analysis, this gave me PRECISELY what I needed... < snip > Thx again, Mr Foster.


You're welcome.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)
Nov 13 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: mm nn | last post by:
Hi, I want to create a table like this: ID Autonum Datefld Date Cat Text Itm Text tCount Number
2
by: Wilder | last post by:
I'm trying to update a field in one table with the minimum values of the field in another table. The two tables are linked via a common field. I want to populate a date field in one table with...
1
by: Glenn P. | last post by:
Sorry, CDMA, I searched this NG on several combinations of words, but I didn't find a relevant hit, so here's my newbie question: I have an Access 2002 table which contains data extracted from...
7
by: rednexgfx_k | last post by:
All, Problem Summary: I've running about 30 make table queries via VBA in Access 2000, and my database goes from 14,000k to over 2,000,000k. In addition, the longer the procedure runs, the...
11
by: Dixie | last post by:
How can I programatically, take some Date/Time fields present in a table in the current database and change their type to text? dixie
2
by: x | last post by:
hi i am a pilot by profession. i want to create a database of my logbook using ms access 2002. i am facing a problem regarding the format of time field. when i select "Data/Time" data type for my...
5
by: laurentc | last post by:
Dear all, I have several tables based on exactly the same fields (Key/Date/Price1/Price2). I do some statistics on the prices. However, as I have many different tables (the tables are...
1
by: sesling | last post by:
I need some help with a date/time field. We run several processing jobs each day. The start and end times are stored in separate columns. The data is stored as date and time. I want to run a...
4
by: debi.robarts | last post by:
Ok, in my database I have something like this: Date One # of Days to Next Date These calculate a field "Date Two." Because "Date Two" is an expression (calculated by the form), I can't set...
2
by: tomash | last post by:
Hi! I ve got two tables in Access 2007. I want to update a field of DataTable from another table, DataSumTable when two of their fields equals. ( the fields : Name and Period) I tried this...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
14
DJRhino1175
by: DJRhino1175 | last post by:
When I run this code I get an error, its Run-time error# 424 Object required...This is my first attempt at doing something like this. I test the entire code and it worked until I added this - If...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
How does React native implement an English player?
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.