Check for leap year

前端 未结 7 2286
花落未央
花落未央 2020-12-11 01:19

How do I check if a year is a leap year?

I have this code:

declare @year int
set @year = 1968

SELECT CASE WHEN @YEAR =  THEN \'LEAP          


        
7条回答
  •  一生所求
    2020-12-11 02:03

    Not sure how efficient this is compared to the other solutions. But is another option.

    DECLARE @year int = 2016
    SELECT CASE 
      WHEN DATEPART(dayofyear, DATEFROMPARTS(@year, 12, 31)) = 366
      THEN 'LEAP' 
      ELSE 'NOT LEAP' 
    END
    

提交回复
热议问题