Link to home
Create AccountLog in
Avatar of shaz0503
shaz0503

asked on

query to return records where a date field is between now and 3 montsh in the future

All

I need a query to return records where a date field is between now and 3 months in the future.  I thought i had the code right but now i playing silly games....

rgds
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

select *
from table
where [datefield] between Date() and Dateadd("m",3,Date())

or this one

select *
from table
where [datefield] between dateserial(Year(Date()),month(date()), day(date()) and dateserial(Year(Date()),month(date())+3, day(date())
SOLUTION
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of shaz0503
shaz0503

ASKER

All

Have tried all the above but can't seem to get them to work - keeps saying data type mismatch

this however works...

SELECT EmployeeData.[Employee ID], EmployeeData.[Termination Date]
FROM EmployeeData
WHERE (((EmployeeData.[Termination Date])<Now()+90));
 
but would prefer to be able to add 3 months instead of 90 days if possible

Data in field is set as Date/Time so unsure why a data mismatch

any ideas

Shaz

try this, copy and paste


SELECT EmployeeData.[Employee ID], EmployeeData.[Termination Date]
FROM EmployeeData
WHERE EmployeeData.[Termination Date] between dateserial(Year(Date()),month(date()), day(date()) and dateserial(Year(Date()),month(date())+3, day(date())


ASKER CERTIFIED SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Thank you all

finally got it

rgds

shaz