怎么修改sql数据库中的指定时间

2022-12-18 14:18

2022-12-18 16:59
update 表名 set checktime=replace(cast(checktime as varchar(20)),substring(cast(checktime as varchar(20)),1,10),'2009-3-2' )
绝对能该没一点问题,如果你只想把指定时间改为2009-3-2,则只需把上面substring(cast(checktime as varchar(20)) 改为指定日期如:2010-10-11
更多回答
如果要改成 当天日期的话:
update 表名 set checktime=to_date(to_char(sysdate,'yyyy-mm-dd hh24:mi:ss'),'yyyy-mm-dd hh24:mi:ss') where checktime=to_date('2010-10-11 19:14:43','yyyy-mm-dd hh24:mi:ss')
----如果要这样改的话:2010-10-11 19:14:43 改成 2011-11-11 19:14:43 。就是只改月数的话,
----可以用add_months(date,n)函数
update 表名 set checktime= add_months(checktime,12) where checktime=to_date('2010-10-11 19:14:43','yyyy-mm-dd hh24:mi:ss')
UPDATE tb SET checktime = CONVERT(DATETIME,('2017-10-01 ' + CONVERT(varchar(100),checktime, 24))) where userid = xx
热门问答