很早以前,写过一个函数,是获取二月份的天数。《T-SQL获取二月份天数》https://www.cnblogs.com/insus/archive/2011/04/22/2025019.html 其中这个函数内就此相关的判断:
SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Insus.NET -- Create date: 2019-05-09 -- Update date: 2019-05-09 -- Description: 指定日期,判断其所属年份是否为闰年 -- ============================================= CREATE FUNCTION [dbo].[svf_IsLeapYear] ( @InputDate DATETIME ) RETURNS BIT AS BEGIN DECLARE @rtv BIT = 0 IF (YEAR( @InputDate ) % 4 = 0 AND YEAR( @InputDate ) % 100 != 0) OR YEAR( @InputDate ) % 400 = 0 SET @rtv = 1 RETURN @rtv END GO
演示使用这个函数: