C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !






Function to Find out a Leap Year


Posted Date: 24 Apr 2008    Resource Type: Code Snippets    Category: Date & Time

Posted By: @@@ Hyderabadi Biryani @@@       Member Level: Diamond
Rating:     Points: 3



Following code sample is a sql function that returns if a given year is a leap year or not.

For example, if the input date is a date belonging to 2008, the bit returned is 1.

Similarly, if the date is one belonging to 2007, the bit returned is 0.

The logic for a leap year is that the year is divisible by 4 and not by 100. But if it divisible by 400 then, it is a leap year.

For example, 2000 is a leap year because it is divisible by 400. But 2100 is not because it is divisible by 100 and not by 400.



CREATE FUNCTION [dbo].[fn_IsLeapYear] ( @pDate DATETIME )
RETURNS BIT
AS
BEGIN

IF (YEAR( @pDate ) % 4 = 0 AND YEAR( @pDate ) % 100 != 0) OR
YEAR( @pDate ) % 400 = 0
RETURN 1

RETURN 0

END
GO





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sql function to compute leap year  .  Sql function for a leap year  .  Leap year function  .  Leap year calculation  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Different types of Date Formats
Previous Resource: Function to Count Number of Days in a Month
Return to Discussion Resource Index
Post New Resource
Category: Date & Time


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

silicone halloween masks

Contact Us    Privacy Policy    Terms Of Use