CFLib.org – Common Function Library Project

DaysTilBirthday(birthdate)

Last updated February 12, 2002

Version: 1 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 0 time(s). Average Rating: 0

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:

view plain print about
<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:

view plain print about
<cfscript>
/**
 * 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;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson