Sql server query to find leap year | ASPMANTRA | Asp.Net,MVC,AngularJs,Jquery,Javascript,Sql Server AND WCF snippets and tutorial

Sql server query to find leap year

In this article I am going to explain how to detect the leap year in Sql server.


Implementation:

Run the below given query to detect LEAP year.
Method 1:
DECLARE @date date
DECLARE @year int
SET @date = GETDATE()
SET @year = YEAR(getdate())

SELECT CASE WHEN (
 (@year % 4 = 0) and (@year % 100 != 0) or
        (@year % 400 = 0)
)
then 'YES' else 'NO'
END
AS [Is Leap year?]

Method 2:

if datepart(dd, cast(cast(datepart(yy, getdate()) as varchar) + '-02-28' as datetime) + 1) = 29
print 'Is Leap Year'
else
print 'Is not Leap Year'



Post a Comment

[blogger]

MKRdezign

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget