Not yet rated

Problem

Need to output the number of till or past a date?

Solution

Simple dateDiff solution.

Detailed explanation

<cfset endDate = createDate(2010, 1, 1)>

<cfset numberOfDaysTill = dateDiff("d", now(), endDate)>

<cfif numberOfDaysTill gt 0>
    <cfoutput>#numberOfDaysTill# day(s) till New Years.</cfoutput>
<cfelseif numberOfDaysTill is 0>
    <cfoutput>Happy New Years</cfoutput>
<cfelse>
    <cfoutput>New Years was #abs(numberOfDaysTill)# day(s) ago.</cfoutput>
</cfif>


+
This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License. Permissions beyond the scope of this license, pertaining to the examples of code included within this work are available at Adobe.

Report abuse

Related recipes