Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help - MS Access query

Status
Not open for further replies.

pmaths

MIS
Feb 15, 2007
37
GB
Hi,

I need to create a query that will report all records that occur within 5 days of the current date.

I've tried the following syntax with no real joy:

>now()-"5"
Returns all records greater than the current date - Seems to ignore the "-5".

>now()+"5"
Same as above.

Between Date() And Date()+"6"
I've had to enter "6" to include the fifth day after today - unfortunatly this syntax also returns dates where it is just the day date that is within 5 days. i.e. as well as returning 17/02/07 it would return records that are dated 17/03/07 - 18/04/07 - 16/05/07 etc...

Between Date() And (Date()+Date(6))
Same as above.

If anybody can advise me I would really appreciate it.

Cheers
 
Have you tried:

[tt]>date()+5[/tt]

Or

[tt]>DateAdd("d",5,Date())[/tt]
 
I think you are looking for this:

Code:
>DateAdd("d",-5,Date())

Hope it helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
Hi - thanks for the swift responses.

Unfortunatly those suggestions return all records after the current date - it would appear that the bit after >Date or >DateAdd is being ignored...

 
Or you are storing Dates in a text column?

Ignorance of certain subjects is a great part of wisdom
 
Or if you want 5 days on either side of current date:

Code:
where datecol >DateAdd("d",-5,Date())
and datecol < DateAdd("d", 5, Date())

Hope this helps,

Alex

Ignorance of certain subjects is a great part of wisdom
 
It is a little odd, too, that Date()+5 (or -5) does not work. It is commonly used in Access queries.
 
How true. Pmaths, can you post the SQL for your entire query?

Ignorance of certain subjects is a great part of wisdom
 
Guys - thanks for you help on this - I have found the problem. Basically our Quality dept have had a database written by an external company and the date field I'm looking at has been given a "text" data type. I've just changed it to Date/Time and guess what? All is good...

So basic a problem I just did'nt think about it...

Cheers again guys - I really appreciated your responses.

Pete.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top