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?
我有一个MySQL表。什么是sql语句看起来要添加说2天到表中的当前日期值?
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?
这增加了一秒的值,我不想更新时间,我想添加两天?
8 个解决方案
#1
71
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.
这种方法也适用于datetime。
#2
6
UPDATE table SET nameofdatefield = ADDDATE(nameofdatefield, 2) WHERE ...
#3
4
This query stands good for fetching the values between current date and its next 3 dates
此查询适用于获取当前日期与其后3个日期之间的值
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.
这最终将为当前日期添加额外3天的缓冲区。
#4
2
update tablename set coldate=DATE_ADD(coldate, INTERVAL 2 DAY)
#5
1
SELECT DATE_ADD(CURDATE(), INTERVAL 2 DAY)
#6
1
For your need:
根据您的需要:
UPDATE classes
SET `date` = DATE_ADD(`date`, INTERVAL 2 DAY)
WHERE id = 161
#7
1
DATE_ADD(FROM_DATE_HERE, INTERVAL INTERVAL_TIME_HERE DAY)
will give the Date after adjusting the INTERVAL
调整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
0
SET date = DATE_ADD( fieldname, INTERVAL 2 DAY )
#1
71
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.
这种方法也适用于datetime。
#2
6
UPDATE table SET nameofdatefield = ADDDATE(nameofdatefield, 2) WHERE ...
#3
4
This query stands good for fetching the values between current date and its next 3 dates
此查询适用于获取当前日期与其后3个日期之间的值
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.
这最终将为当前日期添加额外3天的缓冲区。
#4
2
update tablename set coldate=DATE_ADD(coldate, INTERVAL 2 DAY)
#5
1
SELECT DATE_ADD(CURDATE(), INTERVAL 2 DAY)
#6
1
For your need:
根据您的需要:
UPDATE classes
SET `date` = DATE_ADD(`date`, INTERVAL 2 DAY)
WHERE id = 161
#7
1
DATE_ADD(FROM_DATE_HERE, INTERVAL INTERVAL_TIME_HERE DAY)
will give the Date after adjusting the INTERVAL
调整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
0
SET date = DATE_ADD( fieldname, INTERVAL 2 DAY )