Search code examples
mysqldatetimedateadd

MySQL SELECT add days interval to datetime column


I have a column in my database called SHARE_DATE. I'd like to be able to select all records where SHARE_DATE + 7 DAYS is greater than today.

I've tried the query below but am not getting any of the records that I should. I feel like I'm close but can't quite figure it out. Thanks in advance for any help!

SELECT * FROM TABLE_shares WHERE DATE_ADD(DATE_SHARE, INTERVAL +7 DAY) > NOW();

Solution

  • Per comments resolved with:

    SELECT * FROM
    TABLE_shares
    WHERE DATE_SHARE > DATE_SUB(NOW(), INTERVAL 7 DAY)
    

    Which can use a DATE_SHARE index