比较2个日期是否相同

以前写过2篇,关于日期比较的,需求不同,每一篇均有参考价值。

MS SQL日期比较函数https://www.cnblogs.com/insus/archive/2011/06/24/2089005.html

MS SQL两个日期比较,获取最大或最小的日期https://www.cnblogs.com/insus/archive/2011/06/24/2089049.html

今天再写一篇,比较2个日期是否相同:

 

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      Insus.NET
-- Create date: 2019-05-15
-- Update date: 2019-05-15
-- Description: 比较2个日期是否相同
-- =============================================
CREATE FUNCTION [dbo].[svf_IsSameDay]
(
    @Date DATETIME, 
    @CompareTo DATETIME
)
RETURNS BIT
AS BEGIN
DECLARE @result int = 0;
    IF DATEDIFF(dd,0,@Date) = DATEDIFF(dd,0,@CompareTo)
        SET @result = 1 
 RETURN @result
END
GO
Source Code

 

实例演示:

 

posted @ 2019-05-15 08:10  Insus.NET  阅读(1049)  评论(0编辑  收藏  举报