IF EXISTS(SELECT TOP 1 * FROM sys.objects WHERE name=N'uF_IsRange_Date' AND [type]='FN') DROP FUNCTION uF_IsRange_Date GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: hehai -- Create date: 2015-11-19 11:01:01 -- Description: 判定时间是否在时间区间范围内。 -- ============================================= CREATE FUNCTION uF_IsRange_Date ( @date DATETIME, -- 时间 @date_Range_min DATETIME, -- 时间区间(起始值) @date_Range_max DATETIME -- 时间区间(结束值) ) RETURNS BIT AS BEGIN DECLARE @return BIT SELECT @return=1 FROM sys.objects WHERE @date BETWEEN @date_Range_min AND @date_Range_max IF @return IS NULL SET @return=0 RETURN @return -- @min_seconds>0 AND @max_seconds>0 END GO -- SELECT dbo.uF_IsRange_Date('2015-11-19','2015-11-19','2015-11-10') DECLARE @date DATETIME=N'2015-11-19 10:10:10' DECLARE @date_Range_min DATETIME=N'2015-11-19 10:10:09' DECLARE @date_Range_max DATETIME=N'2015-11-19 10:10:10' SELECT dbo.uF_IsRange_Date(@date,@date_Range_min,@date_Range_max)