如何更换秒部分?
2016-07-07 16:46:23.057
我想用00代替23:
2016-07-07 16:46:00.057
答案 0 :(得分:0)
set @new_value = dateadd(s, -datepart(s, @old_value), @old_value)
答案 1 :(得分:0)
试试这个
DECLARE @Date datetime = '2016-07-07 16:46:23.057'
DECLARE @NewSeconds int = 0 -- from 0 to 59 - what you want to replace the original seconds with
DECLARE @NewDate datetime
SET @NewDate = DATEADD(ss, @NewSeconds, DATEADD(ss, -DATEPART(ss, @Date), @Date))
SELECT @NewDate
答案 2 :(得分:0)
select CONVERT(varchar(10),getdate(),121) +' ' + right('00'+cast(DATEPART(HOUR,getdate()) as varchar(4)),2)+ ':' + right('00'+cast(DATEPART(MINUTE,getdate()) as varchar(4)),2)+ ':00:' + right('000'+cast(DATEPART(MS,getdate()) as varchar(4)),3)