I want to select rows from the datetime now till 7 days in the future, how can I do this? Read alot about the date function of mysql but cant figure it out, this is the MySQL code:
SELECT id, date_format(datum, '%d/%m') AS date,
date_format(datum, '%H:%i') AS time, date
FROM wedstrijden
WHERE date >= now()
ORDER BY datum asc
I have to do something with:
date >= now() till 7 days further
To get yesterday's date, you need to subtract one day from today's date. Use GETDATE() to get today's date (the type is datetime ) and cast it to date . In SQL Server, you can subtract or add any number of days using the DATEADD() function. The DATEADD() function takes three arguments: datepart , number , and date .
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.
If this is SQL Server, BETWEEN CONVERT(date, GETDATE()) AND DATEADD(DD, -7, CONVERT(date, GETDATE())) .
I would submit that the most elegant way would be:
WHERE `date` BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 7 DAY)
Edit: this doc page is like the most useful thing ever. Bookmark it, because it is totally handy.
You could use the INTERVAL modifier to add a week to the current time as follows:
...WHERE date >= NOW() AND date <= NOW() + INTERVAL 7 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