sql server存储过程中 判断时间字段是否在当前时间前后5分钟以内 该怎么写

2025-03-07 11:05:41
推荐回答(2个)
回答1:

select abs(datediff(s,'2012-05-22 14:21:25',getdate()))<=300

就是通过datediff函数比较两个时间的秒数差,绝对值在300秒以内

回答2:

where ‘2012-05-22 10:30’ between dateadd(minute,-5, GETDATE()) and dateadd(minute,5, GETDATE())