In this article I am going to explain how to detect the leap year in Sql server.
In the previous article I have explained how to get first and last date of year,count total number of days in year in Sql server, how to get list of allmonth’s name in Sql server, how to get year calendar with months name andnumber of days in sql server and how to validate corporate or business emailaddress in asp.net using RegularExpression.
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'
AS [Is Leap year?]
if datepart(dd, cast(cast(datepart(yy, getdate()) as varchar) + '-02-28' as datetime) + 1) = 29
print 'Is Leap Year'
print 'Is not Leap Year'
What do you think about this article?
If you found this article useful, please share and follow on Facebook, Twitter, Google Plus and other social media websites. To get free updates subscribe to newsletter. Please put your thoughts and feedback in comments section.