Validating Leap year using ISDATE function

There can be several methods of validating a Leap year (which has 366 days) but using ISDATE function is one of the methods.

Consider the following code

declare @year smallint
set @year=2000
select isdate(cast(@year as char(4))+'0229') as is_leap_year

The result is 1

The idea is to create a date value of 29th February of that year and see if it is a valid date using ISDATE function. If ISDATE returns 1 then it is a Leap Year if it returns 0, it is not a Leap Year



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s