Mysql时间加减函数为date_add()、date_sub()
定义和用法
DATE_ADD() 函数向日期添加指定的时间间隔。
DATE_SUB() 函数向日期减少指定的时间间隔。
语法
DATE_ADD(date,INTERVAL expr type)
DATE_SUB(date,INTERVAL expr type)
date 参数是合法的日期表达式。
expr参数是您希望添加的时间间隔。
type 参数可以是下列值:
Type 值
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR
YEAR_MONTH
例如:
update table_name set EndTime = DATE_ADD(BeginTime,INTERVAL 1 day) where id = 123
即修改这条记录的结束时间使其等于开始时间加1天