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

前端 未结 7 513
抹茶落季
抹茶落季 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 01:58

    How about this: 

    select * from fab_scheduler where custid = 1334666058 and eventdate = eventdate + INTERVAL 1 DAY
    
    0 讨论(0)
  • 2020-12-13 02:03

    It`s possible to use MySQL specific syntax sugar:

    SELECT ... date_field + INTERVAL 1 DAY
    

    Looks much more pretty instead of DATE_ADD function

    0 讨论(0)
  • 2020-12-13 02:07

    If you are able to use NOW() this would be simplest form:

    SELECT * FROM `fab_scheduler` WHERE eventdate>=(NOW() - INTERVAL 1 DAY)) AND eventdate<NOW() ORDER BY eventdate DESC;
    

    With MySQL 5.6+ query abowe should do. Depending on sql server, You may be required to use CURRDATE() instead of NOW() - which is alias for DATE(NOW()) and will return only date part of datetime data type;

    0 讨论(0)
  • 2020-12-13 02:08
    $date = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
    

    Or, simplier:

    date("Y-m-d H:i:s", time()+((60*60)*24));
    
    0 讨论(0)
  • 2020-12-13 02:14

    Have a go with this, as this is how I would do it :)

    SELECT * 
    FROM fab_scheduler
    WHERE custid = '123456'
    AND CURDATE() = DATE(DATE_ADD(eventdate, INTERVAL 1 DAY))
    
    0 讨论(0)
  • 2020-12-13 02:16

    You can try this:

    SELECT DATE(DATE_ADD(m_inv_reqdate, INTERVAL + 1 DAY)) FROM  tr08_investment
    
    0 讨论(0)
提交回复
热议问题