CFLib.org – Common Function Library Project

DaysTilChristmas()

Last updated October 4, 2002

author

Larry Juncker

Version: 2 | Requires: CF5 | Library: DateLib

Description:
Returns the number of days left before Christmas day of the current year. If Christmas has passed, returns the number of days till next year's Christmas.

Return Values:
Returns a number.

Example:

<cfoutput>Are you Ready?  ONLY #DaysTillChristmas()# days till Christmas!</cfoutput>

Parameters:

No arguments.

Full UDF Source:

/**
 * Returns an integer of the days left before Christmas.
 * Version 2 by Ken McCafferty
 * 
 * @return Returns a number. 
 * @author Larry Juncker (ljuncker@aljcompserv.com) 
 * @version 2, October 4, 2002 
 */
function DaysTillChristmas() {
	var ChristmasDayOfYearThisYear =
DayofYear(CreateDate(Year(Now()),12,25));
	var ChristmasDayOfYearNextYear =
DayofYear(CreateDate(Year(Now()) + 1,12,25));
	var TodaysDayOfYear = DayofYear(Now());
	var DaysThisYear=DaysInYear(Now());
	  //Christmas coming
	if (ChristmasDayOfYearThisYear gt TodaysDayOfYear){
	   return ChristmasDayOfYearThisYear -
TodaysDayOfYear;
	}
	 //Christmas has passed
	if (TodaysDayOfYear gt ChristmasDayOfYearThisYear){
	 return DaysThisYear-TodaysDayOfYear +
ChristmasDayOfYearNextYear;
	}
		
	return 0;
}
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