Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Leap Year 1

Status
Not open for further replies.

VBXL

Programmer
Joined
Jul 10, 2001
Messages
198
Location
GB
Hi

Does anybody know how to find out if a year is a Leap Year

Cheers

xplain
 

Let SQL Server tell you by using the IsDate function.

If IsDate('02/29/2000')=1
Print 'Is Leap Year'
Else
Print 'Is Not Leap Year'

Check the current year:

If isdate('02/29/'+cast(year(getdate()) As char(4)))=1
Print 'Is Leap Year'
Else
Print 'Is Not Leap Year'

Alternate syntax:
If IsDate('02/29/'+ltrim(str(year(getdate()))))=1
Print 'Is Leap Year'
Else
Print 'Is Not Leap Year' Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Or generically. A year is a leap year as long as:

It is divisible by 4 and
(It is not divisible by 100 or it is divisible by 400)


In other words 1900 was not a leap year, 2000 was, 2100 will not be.



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top