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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
Method 2
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;
Method 3
I am also posting the query which worked for me
where matchdate BETWEEN CURDATE() AND DATE_ADD(CURDATE(),INTERVAL 7 DAY)
This worked if above example doesn’t work then try this.
Method 4
What i use to get all the data from 7 days back till now from the database:
SELECT * FROM wedstrijden WHERE DATE(date_from_table) > CURDATE() + INTERVAL 7 DAY
Method 5
Something like:
"...WHERE date >= NOW() AND date <= ADDTIME(NOW(), 168:00:00)..."
should accomplish what you’re looking for. The 168:00:00 is a bit specific for your needs, ADDTIME takes any datetime format.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0