Detect Leap Year

Description: Detect leap years (useful for calendar functions, scheduling, etc).

SELECT YEAR,
       DECODE( MOD(YEAR, 4), 0,
          DECODE( MOD(YEAR, 400), 0, 'Leap Year',
             DECODE( MOD(YEAR, 100), 0, 'This is not a Leap Year', 'This is a Leap Year')
          ), 'This is not a Leap Year'
       ) AS leap_year_indicator
FROM   my_table
/

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.