How can I calculate datediff between 2 records?

  • Thread starter Thread starter ccIces
  • Start date Start date
C

ccIces

Guest
Hello all,
I have a data table that lists user log ins sequentially by date. I need to write a function for use in a update query that will calculate the datediff in minutes between each change in user log in.
My table loogs like this
aaa123, stn1, 2005-08-08 12:00
bbb222, stn1, 2005-08-08 13:00
ccc333, stn1, 2005-08-08 14:00
and I need to end up with this:
aaa123, stn1, 2005-08-08 12:00 60(or time however it is expressed)
bbb222, stn1, 2005-08-08 13:00 60
ccc333, stn1, 2005-08-08 14:00 60

the way I figure it I need a function in my query similar to this
expr1: datediff( "n", starttime, endtime)
but I need to figure out how to put the end time in there which is the start time of the next record in the table.
 
Hello ccIces

You could do all of the processing using a recordset and vba instead of in a query, then pass the required variables to your update query.

Bryan
 
I can see the logic of how to do it, I need help telling that to the computer to make it happen.
I just can't seem to figure out how to subtract one records time from another. Can someone suggest a function that would grab the next records value so I can use it in the calculation?
The table fields are ID, Lane, Date
so I need something that
makes a recordset
takes the current record and store the date value to a variable
move to the next record and subtract that date value from the variable
show the resulting value in a new column in the same table.
 

Users who are viewing this thread

Back
Top Bottom