I need to notify customers the day before the game starts, i.e., select all the records for which the date is the next day (00: 00-24: 00).

This query selects the records of the previous day:

"SELECT * FROM table WHERE meta_value BETWEEN CURDATE() - INTERVAL 1 DAY AND CURDATE()" 

I tried to play with him, something does not work.

So, too, does not work:

 SELECT FROM table WHERE meta_value BETWEEN CURDATE() + INTERVAL 1 DAY AND CURDATE() 

Found:

 SELECT * FROM table WHERE meta_value > NOW() AND meta_value < NOW() + INTERVAL 1 DAY 

    1 answer 1

    As the manual explains , the expression

     expr BETWEEN min AND max 

    is equivalent to

     min <= expr AND expr <= max 

    If you take for consideration 2018-10-18 (tomorrow), it gets you asking

     '2018-10-18' <= '2018-10-18' and '2018-10-18' <= '2018-10-17' 

    The second condition is expectedly impossible. Simply put, you have at least confused the arguments in some places.


    If your date field is a meta_value , then a strict comparison is enough:

     where meta_value = (CURDATE() + INTERVAL 1 DAY) 

    If this is a timestamp or datetime - then an interesting question is where exactly should the next day be counted Day on request launch time? Then:

     where meta_value between now() and now() + interval 1 day 

    Next calendar day? Then:

     where meta_value >= curdate() + interval 1 day and meta_value < curdate() + interval 2 day 

    (the next day is the time starting from tomorrow (+1 day) and ending the day after tomorrow (+2 days), but not capturing them - therefore between does not fit here)

    PS: you can meet the possibility to make where date(meta_value) = curdate() + INTERVAL 1 DAY - note that this query will give the correct result, but cannot use the index by meta_value.

    • Thanks, I found it myself - sergeygusev