• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 284
  • Last Modified:

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

0
matthewdacruz
Asked:
matthewdacruz
  • 3
1 Solution
 
johanntagleCommented:
Try:

BETWEEN MONTH(NOW()) AND MONTH(DATE_ADD(NOW(), INTERVAL 3 MONTH))
0
 
johanntagleCommented:
BETWEEN clause just has:

BETWEEN <start value> AND <end value>.

To complete your solution, it should be:

AND month(theme_keyword_promotiontracker2.PP_dateDue)
BETWEEN MONTH(NOW()) AND MONTH(DATE_ADD(NOW(), INTERVAL 3 MONTH))
0
 
matthewdacruzAuthor Commented:
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...
0
 
johanntagleCommented:
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())
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now