ms access - select data by month sql -


i have table consisting of:

product_id (number), product_name (varchar), expired_date (datetime) 

i need select products expired on next 6 months. created statement, doesn't give me error message, guess it's not working because returns no result.

the statement:

select prod.product_id, prod.product_name, prod.expired_date (month(prod.expired_date)) - month(date()) = 6 

where did go wrong?

additional question :

i want records expired on sixth month month selected well. example, 6 months january 2016. 1 of record has expired_date in january 16, 2016 , today july 06, 2015. there few days remaining until become whole 6 months, record not selected. should select of records expired in january?

note: i'm working ms access.

instead, want this:

where prod_expired_date < date_add(curdate(), interval 6 month) 

month() returns month number, 1 12. not want.

i should add, if want things expire in future:

where prod_expired_date >= curdate() ,       prod_expired_date < date_add(curdate(), interval 6 month) 

edit:

in ms access, following should work:

where prod_expired_date < dateadd("m", 6, now())  

edit ii:

that bit trickier. can go last day of previous month , add 7 months:

where prod_expired_date < dateadd("m", 7, dateadd("d", -day(now()), now())  

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -