Link to home
Start Free TrialLog in
Avatar of matthewdacruz
matthewdacruzFlag for United Kingdom of Great Britain and Northern Ireland

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
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))

Open in new window

Avatar of johanntagle
johanntagle
Flag of Philippines image

Try:

BETWEEN MONTH(NOW()) AND MONTH(DATE_ADD(NOW(), INTERVAL 3 MONTH))
ASKER CERTIFIED SOLUTION
Avatar of johanntagle
johanntagle
Flag of Philippines image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of matthewdacruz

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...
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_promotiontracker2.PP_dateDue)=year(now())