calculate days between records and between two columns in the gro

I

IP

I need to calculate days between Discharge Date and next Admit Date in the
group of records. For example,

FirstName LastName ADate DDate Cycle

John Lee 5/10/2009 5/20/2009
John Lee 5/30/2009 5/31/2009 10
John Lee 6/10/2009 6/15/2009 10
Ann Sim 8/11/2009 8/15/2009
Ann Sim 9/01/2009 9/02/2009 16

There must be a way of doing this. I would greatly appreciate any help.
 
G

golfinray

Usually, you use Datediff to calculate. Like this:
Datediff("d",[firstdate],[seconddate])
The "d" is for days.
 
I

IP

It would work if I need date diff in the same record. But I need ADate in one
record, but DDate in the previous, and in the group.

Thank you

golfinray said:
Usually, you use Datediff to calculate. Like this:
Datediff("d",[firstdate],[seconddate])
The "d" is for days.
--
Milton Purdy
ACCESS
State of Arkansas


IP said:
I need to calculate days between Discharge Date and next Admit Date in the
group of records. For example,

FirstName LastName ADate DDate Cycle

John Lee 5/10/2009 5/20/2009
John Lee 5/30/2009 5/31/2009 10
John Lee 6/10/2009 6/15/2009 10
Ann Sim 8/11/2009 8/15/2009
Ann Sim 9/01/2009 9/02/2009 16

There must be a way of doing this. I would greatly appreciate any help.
 
I

IP

I will refraise this . I want to calculate days between two columns , but
between current and previous records. Is it possible to do?
Thank you very much in advance.
 
G

golfinray

No. Not without a lot of steps. I think it would probably be easier then to
maybe just have 2 tables, one that includes each date, then assign a record
number as a primary key then join the two on the key and query. Trying to
query from a different record will be difficult.
 
J

John Spencer

Do you have a primary key that identifies the person? If so life will be
easier. If not, then

SELECT FirstName, LastName, ADate, DDate
, (Select Max(DDate)
FROM SomeTable as Temp
WHERE Temp.FirstName = SomeTable.FirstName
AND Temp.LastName = SomeTable.LastName
AND Temp.DDate < SomeTable.ADate) as PriorDischarge
, ADate -
(Select Max(DDate)
FROM SomeTable as Temp
WHERE Temp.FirstName = SomeTable.FirstName
AND Temp.LastName = SomeTable.LastName
AND Temp.DDate < SomeTable.ADate) as Cycle
FROM SomeTable


If you don't want to see the prior Discharge date then remove the subquery for
PriorDischarge from the SELECT clause of the query.



John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
I

IP

Thank you so much for looking into it. I will try this way. I think it must
work. But if you know the way to do it in the query or in VBA, I would love
to know it.

Thank you again
 
I

IP

Thank you so much ! It is exactly what I need.
What a greate thing these discussions are!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top