MySQL: How to add one day to datetime field in query

前端 未结 7 520
抹茶落季
抹茶落季 2020-12-13 01:36

In my table I have a field named eventdate in datetime format like 2010-05-11 00:00:00.

How do i make a query so that it adds

7条回答
  •  温柔的废话
    2020-12-13 02:20

    You can use the DATE_ADD() function:

    ... WHERE DATE(DATE_ADD(eventdate, INTERVAL -1 DAY)) = CURRENT_DATE
    

    It can also be used in the SELECT statement:

    SELECT DATE_ADD('2010-05-11', INTERVAL 1 DAY) AS Tomorrow;
    +------------+
    | Tomorrow   |
    +------------+
    | 2010-05-12 |
    +------------+
    1 row in set (0.00 sec)
    

提交回复
热议问题