Search code examples
mysql

Getting a next week date


Using MySQL

ID Date

001 2010-08-01
002 2010-08-15
003 2010-08-22
...
....

Query

select ID, Date from table where date < curdate + 7; 

The above query is not working, it showing error.

How to get date upto nextweek date, I don't want to mentioned the date, it should calculate the systemdate + 7 days.

For Example

Today is 2010-06-30,

So it should take a value upto 2010-07-06

How to make a query for this condition....?


Solution

  • Using the DATE_ADD() function:

    ... WHERE date < DATE_ADD(CURDATE(), INTERVAL 7 DAY);
    

    using an operator:

    .... WHERE date < CURDATE() + INTERVAL 7 DAY
    

    reference on date_add

    I'm assuming that by curdate, you mean the function and not a column name. If it's a column name, change accordingly (although I wouldn't name a column after an existing mySQL function.)