[SOLVED] MySQL Where date between 9 and 10 days

Issue

I’m trying to make a query that will select all my users who’s donor status is ending within 10 days.
As i only want to send the message once I want to select all the users who has their donor status ending between 10 and 9 days ahead.

The Donor end date is in this format: 0000-00-00 00:00:00

This is the query I’m currently working around with:

SELECT UserID FROM users_info WHERE donorEnd BETWEEN (NOW() + INTERVAL 10 DAY) AND (NOW() + INTERVAL 9 DAY)

Solution

I think you problem is that you are adding a time not a date: NOW() + INTERVAL 9 DAY = 2015-02-27 19:19 not 2015-02-27 00:00
Try use ADDDATE with CURDATE():

SELECT UserID FROM users_info WHERE donorEnd BETWEEN DATE_ADD(CURDATE(), INTERVAL 9 DAY) AND DATE_ADD(CURDATE(), INTERVAL 9 DAY)

Answered By – user3558040

Answer Checked By – Jay B. (BugsFixing Admin)

Leave a Reply

Your email address will not be published.