判斷指定年份是否為閏年,Insus.NET也曾經寫過2篇《判斷是否是閏年》https://www.cnblogs.com/insus/p/10865051.html 和 《指定日期,判斷其所屬年份是否為閏年》https://www.cnblogs.com/insus/p/10841868.html ...
判斷指定年份是否為閏年,Insus.NET也曾經寫過2篇《判斷是否是閏年》https://www.cnblogs.com/insus/p/10865051.html 和
《指定日期,判斷其所屬年份是否為閏年》https://www.cnblogs.com/insus/p/10841868.html
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Insus.NET -- Create date: 2019-07-01 -- Update date: 2019-07-01 -- Description: 指定年份是否為閏年 -- ============================================= CREATE FUNCTION [dbo].[svf_IsLeapYear] ( @Year SMALLINT ) RETURNS BIT AS BEGIN DECLARE @rtv BIT = 0 IF (@Year >= YEAR([dbo].[svf_LowDate]()) AND @Year <= YEAR([dbo].[svf_HighDate]())) AND ((@Year % 4 = 0 AND @Year % 100 != 0) OR @Year % 400 = 0) SET @rtv = 1 RETURN @rtv END GOSource Code
上面函數中,還有另外2個自定義函數,可以參考這篇《MS SQL獲取最大值或最小值日期的函數》 https://www.cnblogs.com/insus/archive/2011/06/24/2088857.html
MS SQL 最小年份為1753和最大年份為9999。