Reputation: 69
For example, i want get the data on exact date of today before 60 days.
I have tried the follow query but it select all the records from 60 days ago until today.
(bill_date > DATE_SUB(CURDATE() , INTERVAL 60 DAY)
What i want is the records on 60 days ago. Can anyone help me?
Upvotes: 3
Views: 10341
Reputation: 43564
You have to use =
instead of >
!
SELECT * FROM table
WHERE bill_date = DATE_SUB(NOW(), INTERVAL 60 DAY);
today + 60 days (only this day) using DATE_ADD()
:
SELECT * FROM tableName WHERE bill_date = DATE_ADD(NOW(), INTERVAL 60 DAY);
today - 60 days (only this day) using DATE_SUB()
:
SELECT * FROM tableName WHERE bill_date = DATE_SUB(NOW(), INTERVAL 60 DAY);
all records between now and -/+ 60 days:
SELECT * FROM tableName
WHERE bill_date BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW();
SELECT * FROM tableName
WHERE bill_date BETWEEN DATE_ADD(NOW(), INTERVAL 60 DAY) AND NOW();
Upvotes: 8
Reputation: 5322
As per my understanding of your question. Try this query. And please do more clear your question.
SELECT * FROM table
WHERE bill_date BETWEEN DATE_SUB(NOW(), INTERVAL 60 DAY) AND NOW();
Upvotes: 1