Reputation: 3986
I have a table named questions
. In that table there is a field call question_date
. Field is datetime.
I want to check all the question those are asked between 5-7 days only.
I have tried below query but I am getting blank output. No records was there.
SELECT * FROM `questions` WHERE `question_date` < NOW() - INTERVAL 5 DAY AND question_date >= NOW()
SELECT * FROM `questions` WHERE `question_date` = DATE(DATE_ADD(NOW(), INTERVAL -2 DAY))
I have checked the below questions:
mysql query to get birthdays for next 10 days
SQL statement to get the date next 2 days from now
Upvotes: 0
Views: 60
Reputation: 81
You can try same below: select * from demo where DAT between DATE_SUB('2017-02-04', INTERVAL 2 DAY) and '2017-02-04'
Upvotes: -1
Reputation: 1970
Use this
SELECT * FROM `questions`
WHERE `question_date` < date_sub(NOW(), INTERVAL 5 DAY) AND question_date >= date_sub(NOW(), INTERVAL 7 DAY)
Upvotes: 3