判断一个日期是不是今天

以前写过一个方法,先去参考《T-SQL判断是否为今天https://www.cnblogs.com/insus/archive/2012/03/22/2411209.html

今天使用一个更加简单的方法来实现:

 

SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:      Insus.NET
-- Create date: 2019-05-15
-- Update date: 2019-05-15
-- Description: 判断日期是不是今天
-- =============================================
CREATE FUNCTION [dbo].[svf_IsToday]
(
    @Date DATETIME
)
RETURNS BIT
AS 
BEGIN
    RETURN CASE WHEN DATEDIFF(dd,0,@Date) = DATEDIFF(dd,0,CURRENT_TIMESTAMP) THEN 1 ELSE 0 END
END
GO
Source Code

 

实例演示:

 

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