判断指定年份是否为闰年,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 GO
上面函数中,还有另外2个自定义函数,可以参考这篇《MS SQL获取最大值或最小值日期的函数》 https://www.cnblogs.com/insus/archive/2011/06/24/2088857.html
MS SQL 最小年份为1753和最大年份为9999。