I have a quick and asap issue.
SELECT `deals`.*
FROM `deals`
WHERE
`is_featured` = 1 AND
`status` = 'active' AND
CURDATE() BETWEEN start_date AND DATE_ADD(end_date, INTERVAL 1 DAY)
ORDER BY `end_date` DESC
LIMIT 1
Is this right?
start_date is “2012-01-11 00:00:00” and end_date is “2012-01-11 23:59:59”.
This is what I wish to show:
I want to show the dealoffer that is between the current datetime and if the is_featured is 1 and status are “active”.
(CURDATE() gives me only date, not time, is this the problem? How can I get current datetime in MySql?).
It should only pick one deal and this deal should be the one with the closest end date from current datetime.
Here is your original query
Replace the BETWEEN with this
and add this index