matthewdacruz
asked on
Mysql Between Date range help in where clause
Hi Experts
I am trying to do a query where I can take the date now and look at data for the next 3 months
I keep getting a syntax error and am not sure if I am doing the query correct.
What is the correct way of doingthis query?
Thanks
I am trying to do a query where I can take the date now and look at data for the next 3 months
I keep getting a syntax error and am not sure if I am doing the query correct.
What is the correct way of doingthis query?
Thanks
WHERE
theme_keyword_promotiontracker2.TK_profileid = 131
AND theme_keyword_promotiontracker2.number > 0
AND theme_keyword_promotiontracker2.PP_dateDue
BETWEEN
MONTH(theme_keyword_promotiontracker2.PP_dateDue)= MONTH(NOW()) AND
MONTH(theme_keyword_promotiontracker2.PP_dateDue)= MONTH(DATE_ADD(NOW(), INTERVAL 3 MONTH))
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks fro the help.
If I wanted to have the end part of the between to be for the last month of the current year do I just add YEAR(NOW() instead of Interval...
If I wanted to have the end part of the between to be for the last month of the current year do I just add YEAR(NOW() instead of Interval...
No. In the previous SQL we were comparing months. Year(now()) will return the 2011 so its not correct comparison. Pls read up on the usage of the time and date functions before you use them. Anyway it should be something like:
between month(now()) and 12
And year(theme_keyword_promoti ontracker2 .PP_dateDu e)=year(no w())
between month(now()) and 12
And year(theme_keyword_promoti
BETWEEN MONTH(NOW()) AND MONTH(DATE_ADD(NOW(), INTERVAL 3 MONTH))