Miguel Vieira Miguel Vieira - 3 months ago 7
MySQL Question

MySQL query rows with dates close to "today's" date

I'm trying to make a query in MySQL to return rows ranging from "yesterday" to some more days ahead.

My column format for dates is datetime, and my script is in PHP (using PDO).

I couldn't find or figure it out myself, It'll be a query to display the date and some more information from rows close to today's date from a certain category.

Is there a way to select dates like that?

Answer

The mysql query can be something on the below lines -

select 
  * 
from 
  sample
where 
    dateCol >= DATE(DATE_SUB(NOW(),INTERVAL XX DAY))
and dateCol <= DATE(DATE_ADD(NOW(),INTERVAL YY DAY))
Comments