Skip to content

Instantly share code, notes, and snippets.

@ststeiger
Created July 1, 2015 15:30
Show Gist options
  • Select an option

  • Save ststeiger/e238c7988438fec8675c to your computer and use it in GitHub Desktop.

Select an option

Save ststeiger/e238c7988438fec8675c to your computer and use it in GitHub Desktop.
Check if year is leap-year
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fu_IsLeapYear]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[fu_IsLeapYear]
GO
-- ========================================================================
-- Author: Stefan Steiger
-- Create date: 09.08.2010
-- Last modified: 09.08.2010
-- Description: Überprüfen ob Jahr ein Schaltjahr ist
-- ========================================================================
-- PRE: Jahr
-- POST: True/False
-- print dbo.fu_IsLeapYear(2010)
CREATE FUNCTION [dbo].[fu_IsLeapYear](@in_year as int)
RETURNS bit
AS
BEGIN
DECLARE @dtleap_date as datetime
DECLARE @iNextDay as int
DECLARE @bIsLeapYear as bit
SET @bIsLeapYear = 'false'
SET @dtleap_date = dbo.fu_dtDateSerial ( 28, 02, @in_year)
SET @iNextDay = DATEPART(d, DATEADD(d, 1, @dtleap_date))
IF (@iNextDay = 29)
SET @bIsLeapYear = 'true'
RETURN @bIsLeapYear
END
GO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment