SQL Server determines whether time is within a certain time interval

Source: Internet
Author: User

IF EXISTS(SELECT TOP 1 *  fromSys.objectsWHEREName=N'uf_isrange_date'  and [type]='FN')    DROP FUNCTIONuf_isrange_dateGOSETAnsi_nulls onGOSETQuoted_identifier onGO-- =============================================--Author:hehai--Create date:2015-11-19 11:01:01--Description: Determines whether the time is within the time range. -- =============================================CREATE FUNCTIONUf_isrange_date (@date DATETIME,--Time    @date_Range_min DATETIME,--time interval (starting value)    @date_Range_max DATETIME        --time interval (end value))RETURNS BIT asBEGIN    DECLARE @return BIT        SELECT @return=1  fromSys.objectsWHERE @date between @date_Range_min  and @date_Range_max    IF @return  is NULL SET @return=0    RETURN @return --@min_seconds >0 and @max_seconds >0ENDGO--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'SELECTDbo.uf_isrange_date (@date,@date_Range_min,@date_Range_max)

SQL Server determines whether time is within a certain time interval

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.