CFLib.org – Common Function Library Project

DaysTilBirthday(birthdate)

Last updated February 12, 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;
}
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