假如要搜索一个ID号码,现在时间是8点整,要求搜索7点40之前的id号,但时间不能超过8点之前的24个小时。
------解决方案--------------------
--try
select * from tbName
where datediff(hour, DateField, getdate()) <24
and datediff(minute, DateField, getdate())> 20
------解决方案--------------------
--try
select * from tbName
where datediff(hour, DateField, getdate()) <24
and datediff(minute, DateField, getdate())> 20
本文介绍了一种使用SQL语句来精确查找指定时间段内的记录的方法。具体来说,通过DATEDIFF函数结合GETDATE()函数,可以有效地筛选出在当前时间前24小时内且早于当前时间20分钟的数据。
451

被折叠的 条评论
为什么被折叠?



