sql - selecting records in mysql db from 1, 7, and 30 days ago with datetime and php -


Im using the following query to target results that are exact X days old with the current results. From time to time SYSDATE () - 30 days of interval and SYSDATE () ID by DESC from

  SELECT *, DATE_FORMAT (datetime, '% m /% d /% y') table  

The problem is its return data from the present day if there is no record present 30 days ago, as well as irrelevant data

is a better way of doing this ?

together Are there. In other words, between 1 and 4 of , the values ​​include values ​​1, 2, 3 and 4. Not just 1 and 4, and not just 2 and 3

If you just want to date from a day that has been done 30 days ago, try it:

  SELECT *, DATE_FORMAT (datetime, '% m /% D /% y ') from the table where date (datetime) = kurt () - interval 30 day order id DESC  

Use CURDATE () Instead SYSDATE () because CURDATE () returns a date without a time component.


Comments