Gopal
Gopal

Reputation: 11982

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....?

Upvotes: 2

Views: 7181

Answers (3)

okumu justine
okumu justine

Reputation: 368

try this.

SELECT ID, date
WHERE date BETWEEN DATE_ADD(CURRENT_DATE(), INTERVAL(8-DAYOFWEEK(CURRENT_DATE())) DAY)
AND DATE_ADD(CURRENT_DATE(), INTERVAL(14-DAYOFWEEK(CURRENT_DATE())) DAY)

Upvotes: -1

shin
shin

Reputation: 1681

Please try this

select ID, Date from table where Date < DATE_ADD(CURDATE(), INTERVAL 7 DAY)

Upvotes: 0

Pekka
Pekka

Reputation: 449435

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.)

Upvotes: 8

Related Questions