Check for leap year

前端 未结 7 2266
花落未央
花落未央 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:24

    Leap year calculation:

    (@year % 4 = 0) and (@year % 100 != 0) or (@year % 400 = 0)
    

    When this is true, then it is a leap year. Or to put it in case statement

    select case when
        (
            (@year % 4 = 0) and (@year % 100 != 0) or
            (@year % 400 = 0)
        ) then 'LEAP' else 'USUAL' end
    ;
    
    0 讨论(0)
提交回复
热议问题