Show records from now() till next 7 days in mysql

前端 未结 5 632
清歌不尽
清歌不尽 2020-12-29 07:22

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 MySQ

相关标签:
5条回答
  • 2020-12-29 07:49

    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;
    
    0 讨论(0)
  • 2020-12-29 07:55

    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.

    0 讨论(0)
  • 2020-12-29 07:57

    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

    0 讨论(0)
  • 2020-12-29 08:10

    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.

    0 讨论(0)
  • 2020-12-29 08:13

    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.

    0 讨论(0)
提交回复
热议问题