日期:2014-05-18 浏览次数:20763 次
select getdate(),convert(varchar(19),dateadd(ms,500,getdate()),120) /* ----------------------- ------------------- 2011-12-12 22:30:19.060 2011-12-12 22:30:19 (1 行受影响) ----------------------- ------------------- 2011-12-12 22:30:30.967 2011-12-12 22:30:31 (1 行受影响) */
------解决方案--------------------
declare [date] datetime='2011-12-12 20:04:25.687' select (case datepart(ms,[date])>500 then dateadd(ss,1,[date]) else [date] end)
------解决方案--------------------
declare @x1 datetime2,@x2 datetime2 declare @y1 datetime,@y2 datetime select @x1='2011-12-12 20:04:25.499', @x2='2011-12-12 20:04:25.501' select @y1=dateadd(s, case when datepart(ms,@x1)<500 then 0 else 1 end, cast(convert(varchar,@x1,23)+' '+convert(varchar,@x1,108) as datetime)), @y2=dateadd(s, case when datepart(ms,@x2)<500 then 0 else 1 end, cast(convert(varchar,@x2,23)+' '+convert(varchar,@x2,108) as datetime)) select @y1 'y1',@y2 'y2' y1 y2 ----------------------- ----------------------- 2011-12-12 20:04:25 2011-12-12 20:04:26 (1 row(s) affected)