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?
12 Answers
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(); 1As 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();