Date Computation

G

Guest

I need to generate a report based on a query which displays a list where
Date1 exceeds Date2 by more than 10 days. My query looks something like this:

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE
[date1]-[date2]>10

Seems like it doesn't work the way I thought it would work. Any suggestions?
Thanks.
 
D

Douglas J. Steele

How did you think it would work, and what's happening instead?

That query should give you what you're looking for (although it'll have
problems with records where either date1 or date2 is null).

To be able to include Null dates, try:

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE (Nz([date1],
Date() + 11)) -Nz([date2], Date())) >10

or

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE DateDiff("d",
Nz([date1], Date() + 11), Nz([date2], Date())) >10
 
G

Guest

Try

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE
DateDiff("d",[date1],[date2]) < -10
 
G

Guest

Thanks.
ck

Ofer Cohen said:
Try

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE
DateDiff("d",[date1],[date2]) < -10

--
Good Luck
BS"D


CK said:
I need to generate a report based on a query which displays a list where
Date1 exceeds Date2 by more than 10 days. My query looks something like this:

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE
[date1]-[date2]>10

Seems like it doesn't work the way I thought it would work. Any suggestions?
Thanks.
 
G

Guest

Douglas, you mean that my formual there should work? Mmm....you were right
about the null dates because no records were selected at first. Later I did
enter some dates for date1 & date2 but still no records were selected.
Anyway, I will try your suggestion and see what happens. Thanks.
ck

Douglas J. Steele said:
How did you think it would work, and what's happening instead?

That query should give you what you're looking for (although it'll have
problems with records where either date1 or date2 is null).

To be able to include Null dates, try:

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE (Nz([date1],
Date() + 11)) -Nz([date2], Date())) >10

or

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE DateDiff("d",
Nz([date1], Date() + 11), Nz([date2], Date())) >10



--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


CK said:
I need to generate a report based on a query which displays a list where
Date1 exceeds Date2 by more than 10 days. My query looks something like
this:

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE
[date1]-[date2]>10

Seems like it doesn't work the way I thought it would work. Any
suggestions?
Thanks.
 
G

Guest

Thanks, Klatuu.
ck

Klatuu said:
WHERE DateDiff("d", [date1], [date2]) > 10


CK said:
I need to generate a report based on a query which displays a list where
Date1 exceeds Date2 by more than 10 days. My query looks something like this:

SELECT [field1], [field2], [date1], [date2] FROM table1 WHERE
[date1]-[date2]>10

Seems like it doesn't work the way I thought it would work. Any suggestions?
Thanks.
 

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