Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sql query where timestamp is 15+ days ago

Tags:

php

mysql

i have this SQL query:

where datetime < DATE_ADD(DATE(now()), INTERVAL 15 DAY) order by datetime ASC 

is this the right query to say where datetime is 15 days or more ago?

like image 604
charlie Avatar asked Oct 28 '25 12:10

charlie


1 Answers

You should use DATE_SUB instead:

where datetime < DATE_SUB(DATE(now()), INTERVAL 15 DAY) order by datetime ASC 
  • DATE_ADD "adds" an interval to the date you start from.
  • DATE_SUB "subtracts" an interval on the date you start from.

See here for documentation.

like image 53
Filipe Silva Avatar answered Oct 30 '25 03:10

Filipe Silva