WHERE startTime <= GetDate() AND GetDate() <= endTime 根据你的之间是否包含边界决定是否需要用 =。
if startTime <= GetDate() and GetDate() <= endTime begin ...... 你要进行的处理过程 end
GETDATE() BETWEEN startTime AND ENDTIME
declare @sdate datetime = '2014-09-10 22.49:00.000', @edate datetime = '2014-09-11 20:00:00.000' if getdate() between @sdate and @edate begin ............... end else begin ............... end
datetime类型直接between and 或者用<和>这些,但是datetime要注意每天的结尾时间是23:59:59.997,而不是999
如果仅是判断到天,那么用DateDiff 比较保险 DECLARE @StartDate DATETIME='9/10/2014' DECLARE @EndDate DATETIME='10/12/2014' SELECT 1 FROM tb1 WHERE DATEDIFF(d,@StartDate,GETDATE())>=0 and DATEDIFF(d,GETDATE(),@EndDate)>=0 -
if GETDATE() >=@startTime and GETDATE()<=@endTime begin end
AND GetDate() <= endTime
根据你的之间是否包含边界决定是否需要用 =。
begin
...... 你要进行的处理过程
end
@edate datetime = '2014-09-11 20:00:00.000'
if getdate() between @sdate and @edate
begin
...............
end
else
begin
...............
end
DECLARE @EndDate DATETIME='10/12/2014'
SELECT 1 FROM tb1 WHERE DATEDIFF(d,@StartDate,GETDATE())>=0 and DATEDIFF(d,GETDATE(),@EndDate)>=0
-
if GETDATE() >=@startTime and GETDATE()<=@endTime
begin
end