简体   繁体   中英

SQL - NOW() + 10 days

I can't find solution, I'm trying to take in my database date of event that are 10 days after now.

I tried :

SELECT * FROM XXX.Vente WHERE date > (now()+40);

and :

SELECT * FROM LeVigneau.Vente WHERE date > now()+INTERVAL 10 DAY;

But it doesn't work. Du you have an idea ? Thanks a lot

You have to use backticks on date, that because DATE is reserved keyword and DATE_ADD function in following:

Syntax

DATE_ADD(date,INTERVAL expr type)

Query

SELECT * FROM LeVigneau.Vente WHERE `date` > DATE_ADD(now(), INTERVAL 10 DAY);

Also use >= or = , It depends on what exactly do you need, to get records only for 10th day from now or from 10 days and later.

For exactly 10 days:

SELECT * FROM LeVigneau.Vente WHERE `date` = DATE_ADD(now(), INTERVAL 10 DAY);

All other solution give more then 10 days, not exactly 10 days.

for 10 days or more:

SELECT * FROM LeVigneau.Vente WHERE `date` >= DATE_ADD(now(), INTERVAL 10 DAY);

尝试:

SELECT * FROM LeVigneau.Vente WHERE date > DATE_ADD(now(), INTERVAL 10 DAY);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM