Jacob Jacob - 1 month ago 9
MySQL Question

Selecting records where a TimeDate = now() =< 2 years from now

Im a bit new to php and sql and I have this problem:

I have a DateTime field called EndDate.

I need to select and only show records that are current.

Ive tried many variations of the following:

SELECT EndDate FROM booking ORDER BY EndDate ASC WHERE EndDate > NOW()

Answer Source

To fulfill your requirement given in the title of your question, use DATE_ADD:

SELECT EndDate FROM booking 
WHERE EndDate >= NOW() AND EndDate < DATE_ADD(NOW(), INTERVAL 2 YEAR) 
ORDER BY EndDate ASC