MySQL add days to a date

匿名 (未验证) 提交于 2019-12-03 08:57: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 + 1 where id = 161 

this adds one second to the value, i don't want to update the time, i want to add two days?

回答1:

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; 


回答2:

UPDATE table SET nameofdatefield = ADDDATE(nameofdatefield, 2) WHERE ... 


回答3:

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.



回答4:

update tablename set coldate=DATE_ADD(coldate, INTERVAL 2 DAY) 


回答5:

SELECT DATE_ADD(CURDATE(), INTERVAL 2 DAY) 


回答6:

For your need:

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


回答7:

 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 


回答8:

SET date = DATE_ADD( fieldname, INTERVAL 2 DAY ) 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!