472,374 Members | 1,325 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,374 software developers and data experts.

Time diff between records

Hi all,
I have a query (query1) which shows scan date, scan time & operator. One
scan = 1 record. What I want to do is create a report based on query 2 from
query1 which shows all the scans AND the difference between each scan.
Something like below. I have spent days on this and can't figure it out.

Date Time Login Diff
04-Dec-03 23:33:12 27478
04-Dec-03 23:33:38 27478 00:00:26
04-Dec-03 23:34:00 27478 00:00:22
04-Dec-03 23:34:21 27478 00:00:21
04-Dec-03 23:35:11 27478 00:00:50

Thanks in advance

Mark
Nov 12 '05 #1
4 4139
Use a subquery to get the most recent login date and time for the same login
number.

That's a matter of typing something like this into the Field row of your
query to create the calculated field:

Seconds: DateDiff("s", (MyTable.Date + MyTable.Time),
(SELECT TOP 1 (Dupe.Date + Dupe.Time) AS PriorTime
FROM MyTable AS Dupe
WHERE ((Dupe.Login = MyTable.Login) AND ((Dupe.Date + Dupe.Time) <
(Mytable.Date + MyTable.Time)))
ORDER BY Dupe.Date DESC; Dupe.Time DESC ) )

This would be considerably more efficient if the date and time were stored
in the one field. Hopefully your fields are not actually called Date and
Time as theser are reserved words in VBA.

Consider adding the primary key to the ORDER BY clause as well, so Access
can distinguish between 2 records that have exactly the same date and time.

If you want the time as a string instead of a number of seconds, see:
http://members.rogers.com/douglas.j....iff2Dates.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:hN************@newsfep3-gui.server.ntli.net...
Hi all,
I have a query (query1) which shows scan date, scan time & operator. One scan = 1 record. What I want to do is create a report based on query 2 from query1 which shows all the scans AND the difference between each scan.
Something like below. I have spent days on this and can't figure it out.

Date Time Login Diff
04-Dec-03 23:33:12 27478
04-Dec-03 23:33:38 27478 00:00:26
04-Dec-03 23:34:00 27478 00:00:22
04-Dec-03 23:34:21 27478 00:00:21
04-Dec-03 23:35:11 27478 00:00:50

Nov 12 '05 #2
Thanks for that Allen,
I've tried what you have suggest but I think I am doing something wrong.
I'll give you a little more background to my problem as I think that may be
the cause.

The database gets it's inputs from a txt file recovered from the works
management system when I run a SQL within it. Towards the end of shift,
there could be anything up to 18,000 entries as the WMS SQL asks for every
single scan during a set shift. The results of that SQL are then pasted into
a single field of my Access database.
Example of txt result is:

04-DEC-2003 22:21:09 Chowdry, Halim 06313 988558 -6 N5608D CCS
LOCA 1 H Picking 14310 725997 Conv
Conv -6 04.12.03H 3

04-DEC-2003 22:22:16 Phillips, Lillian 46517H 988567 -1 N6909A CCS
LOCA 1 H Picking 14362 681311 Conv
Conv -1 04.12.03H 3

My first query ([decode1]) breaks the txt file into relevant fields. The
second ([decode2]) then changes the some of the fields into values and time
rather than just text.

SELECT DISTINCT DateValue([decode].[Date]) AS actdate,
TimeValue([Decode]![Time]) AS acttime, [Name query].[First Name], [Name
query].Surname, Decode.Operator, Decode.[Pic Route], Val([Decode]![QTY]) AS
Qty, Val([Decode]![IP Qty]) AS [IP Qty], Decode.Location, Decode.[To
Location], Decode.Cartons, Decode.PT, Decode.Job, Val([Decode]![RDT]) AS
RDT, Val([Decode]![Trolley]) AS Trolley, Decode.Fromst, Decode.Tost,
Decode.Schedule, Decode.Wv
FROM [Name query] INNER JOIN Decode ON [Name query].Login = Decode.Operator
GROUP BY DateValue([decode].[Date]), TimeValue([Decode]![Time]), [Name
query].[First Name], [Name query].Surname, Decode.Operator, Decode.[Pic
Route], Val([Decode]![QTY]), Val([Decode]![IP Qty]), Decode.Location,
Decode.[To Location], Decode.Cartons, Decode.PT, Decode.Job,
Val([Decode]![RDT]), Val([Decode]![Trolley]), Decode.Fromst, Decode.Tost,
Decode.Schedule, Decode.Wv
WITH OWNERACCESS OPTION;

All of the other querys in the DB are based on the decode2 query.

How would you write the query, given the above information to show the time
difference between each record?

I really appreciate your help with this.

Regards,
Mark

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
Use a subquery to get the most recent login date and time for the same login number.

That's a matter of typing something like this into the Field row of your
query to create the calculated field:

Seconds: DateDiff("s", (MyTable.Date + MyTable.Time),
(SELECT TOP 1 (Dupe.Date + Dupe.Time) AS PriorTime
FROM MyTable AS Dupe
WHERE ((Dupe.Login = MyTable.Login) AND ((Dupe.Date + Dupe.Time) <
(Mytable.Date + MyTable.Time)))
ORDER BY Dupe.Date DESC; Dupe.Time DESC ) )

This would be considerably more efficient if the date and time were stored
in the one field. Hopefully your fields are not actually called Date and
Time as theser are reserved words in VBA.

Consider adding the primary key to the ORDER BY clause as well, so Access
can distinguish between 2 records that have exactly the same date and time.
If you want the time as a string instead of a number of seconds, see:
http://members.rogers.com/douglas.j....iff2Dates.html

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:hN************@newsfep3-gui.server.ntli.net...
Hi all,
I have a query (query1) which shows scan date, scan time & operator.

One
scan = 1 record. What I want to do is create a report based on query 2

from
query1 which shows all the scans AND the difference between each scan.
Something like below. I have spent days on this and can't figure it out.

Date Time Login Diff
04-Dec-03 23:33:12 27478
04-Dec-03 23:33:38 27478 00:00:26
04-Dec-03 23:34:00 27478 00:00:22
04-Dec-03 23:34:21 27478 00:00:21
04-Dec-03 23:35:11 27478 00:00:50


Nov 12 '05 #3
Hi Mark.

It makes sense to import the text file into an Access table.
Combine the date and time into one Date/Time field, and index it.
Then the subquery should be able to find the correct prior date/time value
from the index (instead of having to scan the 18k records), so it should
perform acceptably.

For more info on how to build the subquery, see:
How to Compare a Field to a Field in a Prior Record
at:

http://support.microsoft.com/default...roduct=acc2000

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:jX**************@newsfep3-gui.server.ntli.net...
Thanks for that Allen,
I've tried what you have suggest but I think I am doing something wrong. I'll give you a little more background to my problem as I think that may be the cause.

The database gets it's inputs from a txt file recovered from the works
management system when I run a SQL within it. Towards the end of shift,
there could be anything up to 18,000 entries as the WMS SQL asks for every
single scan during a set shift. The results of that SQL are then pasted into a single field of my Access database.
Example of txt result is:

04-DEC-2003 22:21:09 Chowdry, Halim 06313 988558 -6 N5608D CCS
LOCA 1 H Picking 14310 725997 Conv
Conv -6 04.12.03H 3

04-DEC-2003 22:22:16 Phillips, Lillian 46517H 988567 -1 N6909A CCS
LOCA 1 H Picking 14362 681311 Conv
Conv -1 04.12.03H 3

My first query ([decode1]) breaks the txt file into relevant fields. The
second ([decode2]) then changes the some of the fields into values and time rather than just text.

SELECT DISTINCT DateValue([decode].[Date]) AS actdate,
TimeValue([Decode]![Time]) AS acttime, [Name query].[First Name], [Name
query].Surname, Decode.Operator, Decode.[Pic Route], Val([Decode]![QTY]) AS Qty, Val([Decode]![IP Qty]) AS [IP Qty], Decode.Location, Decode.[To
Location], Decode.Cartons, Decode.PT, Decode.Job, Val([Decode]![RDT]) AS
RDT, Val([Decode]![Trolley]) AS Trolley, Decode.Fromst, Decode.Tost,
Decode.Schedule, Decode.Wv
FROM [Name query] INNER JOIN Decode ON [Name query].Login = Decode.Operator GROUP BY DateValue([decode].[Date]), TimeValue([Decode]![Time]), [Name
query].[First Name], [Name query].Surname, Decode.Operator, Decode.[Pic
Route], Val([Decode]![QTY]), Val([Decode]![IP Qty]), Decode.Location,
Decode.[To Location], Decode.Cartons, Decode.PT, Decode.Job,
Val([Decode]![RDT]), Val([Decode]![Trolley]), Decode.Fromst, Decode.Tost,
Decode.Schedule, Decode.Wv
WITH OWNERACCESS OPTION;

All of the other querys in the DB are based on the decode2 query.

How would you write the query, given the above information to show the time difference between each record?

I really appreciate your help with this.

Regards,
Mark

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
Use a subquery to get the most recent login date and time for the same

login
number.

That's a matter of typing something like this into the Field row of your
query to create the calculated field:

Seconds: DateDiff("s", (MyTable.Date + MyTable.Time),
(SELECT TOP 1 (Dupe.Date + Dupe.Time) AS PriorTime
FROM MyTable AS Dupe
WHERE ((Dupe.Login = MyTable.Login) AND ((Dupe.Date + Dupe.Time) <
(Mytable.Date + MyTable.Time)))
ORDER BY Dupe.Date DESC; Dupe.Time DESC ) )

This would be considerably more efficient if the date and time were stored in the one field. Hopefully your fields are not actually called Date and
Time as theser are reserved words in VBA.

Consider adding the primary key to the ORDER BY clause as well, so Access can distinguish between 2 records that have exactly the same date and

time.

If you want the time as a string instead of a number of seconds, see:
http://members.rogers.com/douglas.j....iff2Dates.html
"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:hN************@newsfep3-gui.server.ntli.net...
Hi all,
I have a query (query1) which shows scan date, scan time & operator.
One
scan = 1 record. What I want to do is create a report based on query 2

from
query1 which shows all the scans AND the difference between each scan.
Something like below. I have spent days on this and can't figure it

out.
Date Time Login Diff
04-Dec-03 23:33:12 27478
04-Dec-03 23:33:38 27478 00:00:26
04-Dec-03 23:34:00 27478 00:00:22
04-Dec-03 23:34:21 27478 00:00:21
04-Dec-03 23:35:11 27478 00:00:50

Nov 12 '05 #4
Fantastic!!!! Thankyou very much for your help.

Mark
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
Hi Mark.

It makes sense to import the text file into an Access table.
Combine the date and time into one Date/Time field, and index it.
Then the subquery should be able to find the correct prior date/time value
from the index (instead of having to scan the 18k records), so it should
perform acceptably.

For more info on how to build the subquery, see:
How to Compare a Field to a Field in a Prior Record
at:

http://support.microsoft.com/default...roduct=acc2000
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:jX**************@newsfep3-gui.server.ntli.net...
Thanks for that Allen,
I've tried what you have suggest but I think I am doing something

wrong.
I'll give you a little more background to my problem as I think that may

be
the cause.

The database gets it's inputs from a txt file recovered from the works
management system when I run a SQL within it. Towards the end of shift,
there could be anything up to 18,000 entries as the WMS SQL asks for every
single scan during a set shift. The results of that SQL are then pasted

into
a single field of my Access database.
Example of txt result is:

04-DEC-2003 22:21:09 Chowdry, Halim 06313 988558 -6 N5608D CCS LOCA 1 H Picking 14310 725997 Conv
Conv -6 04.12.03H 3

04-DEC-2003 22:22:16 Phillips, Lillian 46517H 988567 -1 N6909A CCS LOCA 1 H Picking 14362 681311 Conv
Conv -1 04.12.03H 3

My first query ([decode1]) breaks the txt file into relevant fields. The
second ([decode2]) then changes the some of the fields into values and

time
rather than just text.

SELECT DISTINCT DateValue([decode].[Date]) AS actdate,
TimeValue([Decode]![Time]) AS acttime, [Name query].[First Name], [Name
query].Surname, Decode.Operator, Decode.[Pic Route], Val([Decode]![QTY])

AS
Qty, Val([Decode]![IP Qty]) AS [IP Qty], Decode.Location, Decode.[To
Location], Decode.Cartons, Decode.PT, Decode.Job, Val([Decode]![RDT]) AS
RDT, Val([Decode]![Trolley]) AS Trolley, Decode.Fromst, Decode.Tost,
Decode.Schedule, Decode.Wv
FROM [Name query] INNER JOIN Decode ON [Name query].Login =

Decode.Operator
GROUP BY DateValue([decode].[Date]), TimeValue([Decode]![Time]), [Name
query].[First Name], [Name query].Surname, Decode.Operator, Decode.[Pic
Route], Val([Decode]![QTY]), Val([Decode]![IP Qty]), Decode.Location,
Decode.[To Location], Decode.Cartons, Decode.PT, Decode.Job,
Val([Decode]![RDT]), Val([Decode]![Trolley]), Decode.Fromst, Decode.Tost, Decode.Schedule, Decode.Wv
WITH OWNERACCESS OPTION;

All of the other querys in the DB are based on the decode2 query.

How would you write the query, given the above information to show the

time
difference between each record?

I really appreciate your help with this.

Regards,
Mark

"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:40**********************@freenews.iinet.net.a u...
Use a subquery to get the most recent login date and time for the same

login
number.

That's a matter of typing something like this into the Field row of your query to create the calculated field:

Seconds: DateDiff("s", (MyTable.Date + MyTable.Time),
(SELECT TOP 1 (Dupe.Date + Dupe.Time) AS PriorTime
FROM MyTable AS Dupe
WHERE ((Dupe.Login = MyTable.Login) AND ((Dupe.Date + Dupe.Time) <
(Mytable.Date + MyTable.Time)))
ORDER BY Dupe.Date DESC; Dupe.Time DESC ) )

This would be considerably more efficient if the date and time were

stored in the one field. Hopefully your fields are not actually called Date and Time as theser are reserved words in VBA.

Consider adding the primary key to the ORDER BY clause as well, so Access can distinguish between 2 records that have exactly the same date and

time.

If you want the time as a string instead of a number of seconds, see:
http://members.rogers.com/douglas.j....iff2Dates.html
"Mark Reed" <ma*********@ntlworld.com> wrote in message
news:hN************@newsfep3-gui.server.ntli.net...
> Hi all,
> I have a query (query1) which shows scan date, scan time & operator. One
> scan = 1 record. What I want to do is create a report based on query 2 from
> query1 which shows all the scans AND the difference between each scan. > Something like below. I have spent days on this and can't figure it out. >
> Date Time Login Diff
> 04-Dec-03 23:33:12 27478
> 04-Dec-03 23:33:38 27478 00:00:26
> 04-Dec-03 23:34:00 27478 00:00:22
> 04-Dec-03 23:34:21 27478 00:00:21
> 04-Dec-03 23:35:11 27478 00:00:50


Nov 12 '05 #5

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

Similar topics

1
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2...
6
by: Stefan Behnel | last post by:
Hi! The logging module nicely prepends each line with a formatted date. However, I'm not interested in the actual date but only in the number of milliseconds that passed since the start of the...
2
by: Alberto Santini | last post by:
I ported a Jos Stam's demo about Fluid mech to check the difference of speed between C implementation and Python. I think I achieved good results with Python and there is space to improve, without...
3
by: Chanchito | last post by:
hi there, I am seeking some guidance in regards to creating a query. I would like to be able to have the query display records that have had a certain amount of time pass since the time that is...
9
by: MLH | last post by:
I have a database (datatrek.mdb) with a table named DATA. The table has a date/time field with default value = Now(). It has 100 records in it entered over a 50-minute period. I would like the...
2
by: Viviana R via AccessMonster.com | last post by:
I'm tryin to calculate de difference of time between different records and fields. I have a Report with date, time In, and Time Out fields. EX: Date Time IN Time Out 4/12/05 12:10...
3
by: Richard | last post by:
Hi, Is there any way to get the time difference between Central(US) and GMT in vb.net. I'll appreciate your help/suggestion. Thanks RC
6
by: Jeremy Sanders | last post by:
Hi - I need to add support to a program for dates and times. The built-in Python library seems to be okay for many purposes, but what I would like would be Unix epoch style times (seconds relative...
9
by: Ron Adam | last post by:
I'm having some cross platform issues with timing loops. It seems time.time is better for some computers/platforms and time.clock others, but it's not always clear which, so I came up with the...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...
0
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.