CFLib.org – Common Function Library Project

containsLeapYear(startDate, endDate)

Last updated May 26, 2003

author

Mosh Teitelbaum

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Function that determines if a given date range contains a leap year. Returns true if it contains a leap year, false if not.

Return Values:
Returns a boolean.

Example:

<CFOUTPUT>
	containsLeapYear("1/1/2002", "6/1/2002") = #containsLeapYear("1/1/2002", "6/1/2002")#<br>
	containsLeapYear("1/1/2003", "6/1/2003") = #containsLeapYear("1/1/2003", "6/1/2003")#<br>
	containsLeapYear("1/1/2004", "2/1/2004") = #containsLeapYear("1/1/2004", "2/1/2004")#<br>
	containsLeapYear("1/1/2004", "6/1/2004") = #containsLeapYear("1/1/2004", "6/1/2004")#<br>
</CFOUTPUT>

Parameters:

Name Description Required
startDate Initial date. Yes
endDate Ending date. Yes

Full UDF Source:

/**
 * Function that determines if a given date range contains a leap year.
 * 
 * @param startDate 	 Initial date. (Required)
 * @param endDate 	 Ending date. (Required)
 * @return Returns a boolean. 
 * @author Mosh Teitelbaum (mosh.teitelbaum@evoch.com) 
 * @version 1, May 26, 2003 
 */
function containsLeapYear(startDate, endDate) {
	// Build offsets
	var StartDateYearOffset = DateAdd("yyyy", 1, startDate);
	var StartDateYearOffsetInDays = DateDiff("d", startDate, StartDateYearOffset);
	var EndDateYearOffset = DateAdd("yyyy", 1, Trim(endDate));
	var EndDateYearOffsetInDays = DateDiff("d", endDate, EndDateYearOffset);

	// Return result
	return IIf(StartDateYearOffsetInDays - EndDateYearOffsetInDays GT 0, DE("true"), DE("false"));
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson