CFLib.org – Common Function Library Project

DaysTilBirthday(birthdate)

Last updated February 13, 2002

author

Jason Fuller

Version: 1 | Requires: CF5 | Library: DateLib

Description:
DaysTilBirthday returns the number of days until your next birthday. It should accept any date ColdFusion can parse, and will return an integer. If your birthday happens to be today, it will return zero.

Return Values:
Returns a numeric value.

Example:

<cfset my_birthday = "June 9, 1979">
My birthday is in <cfoutput>#DaysTilBirthday(my_birthday)#</cfoutput> day(s).

Parameters:

Name Description Required
birthdate Birthdate you want to find the number of days until. Accepts any valid date object. Yes

Full UDF Source:

/**
 * Returns number of days until your next birthday.
 * 
 * @param birthdate      Birthdate you want to find the number of days until.  Accepts any valid date object. 
 * @return Returns a numeric value. 
 * @author Jason Fuller (jason@yomamma.com) 
 * @version 1, February 12, 2002 
 */
function DaysTilBirthday(birthdate) {
  var daysRemaining = "";
  if (DateFormat(now(), "MMDD") GT DateFormat(birthdate, "MMDD")) 
    daysRemaining = Int(CreateDate(DatePart("yyyy", now() + 365), DatePart("m", birthdate), DatePart("d", birthdate)) - now() + 1);
  else 
    daysRemaining = Int(CreateDate(DatePart("yyyy", now()), DatePart("m", birthdate), DatePart("d", birthdate)) - now() + 1);
  Return daysRemaining;
}

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