以前寫過一個方法,先去參考《T-SQL判斷是否為今天》https://www.cnblogs.com/insus/archive/2012/03/22/2411209.html 今天使用一個更加簡單的方法來實現: 實例演示: ...
以前寫過一個方法,先去參考《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 GOSource Code
實例演示: