How to get the date of today -30 / -60 days?

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?

1

2 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(); 
1

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(); 

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like