解决方法
是的,只需使用datediff和dateadd函数从任何日期删除时间,然后将一天的小数部分添加到该数字
Declare @aDate DateTime Set @aDate = getDate() Declare @Minutes Integer Set @minutes = 600 -- 10 hours Select DateAdd(day,DateDiff(day,@aDate),0) + @minutes / 1440.0 -- 1440 min/day -- or You could also use the dateadd again... Select DateAdd(minute,@minutes,DateAdd(day,0))
两者都选择在当天上午10:00(或多或少)返回。这是因为,很好,检查出this SO answer
declare @dtTim datetime = getDate() declare @today datetime = dateAdd(day,dateDiff(day,@dtTim ),0) select @dtTim,@today