Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql where date is before now + 2 weeks

How to get the rows out of a MySQL DB where the field date is before NOW + 2 weeks?

I have tried

WHERE date_ready < DATE_SUB(CURDATE(), INTERVAL 2 WEEK)

But that is not the rows returning that I expect.

like image 901
Muiter Avatar asked Sep 03 '25 16:09

Muiter


2 Answers

Or even, now() minus 2 week,

where date_ready < (NOW() - INTERVAL 2 WEEK)

with just date

where date_ready < (CURDATE() - INTERVAL 2 WEEK)
like image 185
Akshay Hegde Avatar answered Sep 05 '25 07:09

Akshay Hegde


You're querying dates that are before today minus two weeks, not plus. You should use date_add instead of date_sub:

WHERE date_ready < DATE_ADD(CURDATE(), INTERVAL 2 WEEK)
-- Here -----------^
like image 35
Mureinik Avatar answered Sep 05 '25 05:09

Mureinik