Pergunta

I have table with one column (date of expiration). I want to select all rows where expiration is between today and one next week. I am using MySQL and InnoDB type.

I try something like this:

SELECT name, expiration 
FROM exp 
WHERE (expiration BETWEEN(CURRENT_DATE, INTERVAL 1 WEEK));

But i have bad syntax. There is error:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') LIMIT 0, 30' at line 3
Foi útil?

Solução

Try this:

SELECT *
FROM exp
WHERE expiration  BETWEEN 
         current_date 
        AND 
         current_date + interval 7 day

demo: --> http://www.sqlfiddle.com/#!2/8598a/2

Outras dicas

This should be the syntax you want:

SELECT name, expiration FROM table WHERE expiration
  BETWEEN
    CURRENT_DATE
  AND
    ADDDATE(CURRENT_DATE, INTERVAL 1 WEEK)

(You need to add the one week to the current date, you cannot just specify the interval standing on its own/as a parameter to BETWEEN)

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top