MySQL add days to a date

前端 未结 9 1649
夕颜
夕颜 2020-11-27 18:35

I have a table in MySQL. What would be the sql statement look like to add say 2 days to the current date value in the table?

UPDATE classes 
SET 
date = date         


        
相关标签:
9条回答
  • 2020-11-27 19:12
    SET date = DATE_ADD( fieldname, INTERVAL 2 DAY )
    
    0 讨论(0)
  • 2020-11-27 19:18
    UPDATE table SET nameofdatefield = ADDDATE(nameofdatefield, 2) WHERE ...
    
    0 讨论(0)
  • 2020-11-27 19:18

    This query stands good for fetching the values between current date and its next 3 dates

    SELECT * FROM tableName
    WHERE columName BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 3 DAY)
    

    This will eventually add extra 3 days of buffer to the current date.

    0 讨论(0)
  • 2020-11-27 19:26

    Assuming your field is a date type (or similar):

    SELECT DATE_ADD(`your_field_name`, INTERVAL 2 DAY) 
    FROM `table_name`;
    

    With the example you've provided it could look like this:

    UPDATE classes 
    SET `date` = DATE_ADD(`date` , INTERVAL 2 DAY)
    WHERE `id` = 161;
    

    This approach works with datetime , too.

    0 讨论(0)
  • 2020-11-27 19:29
    update tablename set coldate=DATE_ADD(coldate, INTERVAL 2 DAY)
    
    0 讨论(0)
  • 2020-11-27 19:29
    SELECT DATE_ADD(CURDATE(), INTERVAL 2 DAY)
    
    0 讨论(0)
提交回复
热议问题