CFLib.org – Common Function Library Project

DaysTilChristmas()

Last updated October 04, 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;
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson