Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to find leap year in sql query

Author  Topic 

itnagaraj
Yak Posting Veteran

70 Posts

Posted - 2010-09-13 : 09:58:48
How to find leap year in sql query

V.NAGARAJAN

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2010-09-13 : 12:09:42
SQL server date functions take leap years into account. But the way you determine a leap year in SQL is the same as anywhere else. All years divisible by 4 are leap years (Year % 4) = 0 except
if a year is divisible by 100 (year % 100) = 0, it is a leap year only if it is also divisible by 400 (year % 400) = 0

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-14 : 05:33:51
If the 60th day falls in February, it is a Leap year

select case when month(dateadd(year,datediff(year,0,getdate()),0)+59)=2 then 'Leap year' else 'Non Leap year' end


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-09-14 : 06:02:01
Also see http://weblogs.sqlteam.com/peterl/archive/2009/02/25/Fastest-LeapYear-checker.aspx
Frank Kalis posted a fast solution.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-09-14 : 06:24:59
quote:
Originally posted by Peso

Also see http://weblogs.sqlteam.com/peterl/archive/2009/02/25/Fastest-LeapYear-checker.aspx
Frank Kalis posted a fast solution.



N 56°04'39.26"
E 12°55'05.63"



Frank is one of the smartest persons in SQL Server world

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -