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
The NOW() function returns the current date and time. Note: The date and time is returned as "YYYY-MM-DD HH-MM-SS" (string) or as YYYYMMDDHHMMSS. uuuuuu (numeric).
Use the DATE_ADD() function if you want to increase a given date in a MySQL database. In our example, we increased each start date by two days.
The DATE_SUB() function subtracts a time/date interval from a date and then returns the date.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With