0

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

halfer
  • 19,824
  • 17
  • 99
  • 186
Roxx
  • 3,738
  • 20
  • 92
  • 155

2 Answers2

3

Use this

SELECT * FROM `questions` 
WHERE `question_date` < date_sub(NOW(), INTERVAL 5 DAY) AND question_date >= date_sub(NOW(), INTERVAL 7 DAY)
Shuddh
  • 1,920
  • 2
  • 19
  • 30
-1

You can try same below: select * from demo where DAT between DATE_SUB('2017-02-04', INTERVAL 2 DAY) and '2017-02-04'

Vu Minh Vuong
  • 81
  • 1
  • 1
  • 6