MySQL add days to a date

前端 未结 9 1651
夕颜
夕颜 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:30
     DATE_ADD(FROM_DATE_HERE, INTERVAL INTERVAL_TIME_HERE DAY) 
    

    will give the Date after adjusting the INTERVAL

    eg.

    DATE_ADD(NOW(), INTERVAL -1 DAY) for deducting 1 DAY from current Day
    DATE_ADD(NOW(), INTERVAL 2 DAY)  for adding 2 Days
    

    You can use like

    UPDATE classes WHERE date=(DATE_ADD(date, INTERVAL 1 DAY)) WHERE id=161
    
    0 讨论(0)
  • 2020-11-27 19:35

    For your need:

    UPDATE classes 
    SET `date` = DATE_ADD(`date`, INTERVAL 2 DAY)
    WHERE id = 161
    
    0 讨论(0)
  • 2020-11-27 19:35

    You can leave date_add function.

    UPDATE `table` 
    SET `yourdatefield` = `yourdatefield` + INTERVAL 2 DAY
    WHERE ...
    
    0 讨论(0)
提交回复
热议问题