Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query WHERE date is more recent than 14 days

Tags:

mysql

I'm trying to find a way to do a request in MySQL such as this one :

SELECT * FROM table WHERE insert_date < '14 days'

From googling, I found two answers :

SELECT * FROM table WHERE insert_date < DateAdd(dd,-14,GetDate())

and

SELECT * FROM table WHERE insert_date < DateAdd(day,Datediff(day,0,getdate()),-14)

So here are my questions :

1) Are there better ways to do this ?

2) What is the difference between the two things I found ?

Thanks

like image 370
François M. Avatar asked Dec 02 '25 15:12

François M.


1 Answers

Your Google'd answers are for SQL Server, not MySQL.

All of them are getting dates older than 14 days ago, not more recent.

So, I think you want:

SELECT *
FROM table
WHERE insert_date > date_sub(curdate(), interval 14 day);
like image 173
Gordon Linoff Avatar answered Dec 04 '25 07:12

Gordon Linoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!