473,402 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 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 2851
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.