sql中时间的一些特殊转换

1.修改时间的秒和微秒

create table a (Dtime datetime);
insert into a
select '2013-08-30 17:59:35' union all
select '2013-09-01 17:59:35' union all
select '2013-09-02 17:59:35' union all
select '2013-09-03 18:59:35'

select * from a

update a set Dtime=dateadd(ss,(rand(checksum(newid()))*60-datepart(ss,Dtime)),Dtime)

update a set Dtime=dateadd(ms,(rand(checksum(newid()))*1000-datepart(ms,Dtime)),Dtime)

select *,rand(checksum(newid()))*60,datepart(ss,Dtime) from a

drop table a

2.时:分:秒格式与整数秒的转换


select convert(varchar(8),dateadd(ss,5000,108),108)

select datediff( s,'00:00:00','23:59:59')

原文地址:https://www.cnblogs.com/lgx5/p/6264997.html