4.27.2007

Cold Fusion DATADIFF function

I did something new with Cold Fusion today at work and I pass this on:


  1. Problem: Need to calculate a time interval between dates.
  2. Solution: datadiff()


In my case, I had to display an icon based on the date calculation. A green dot if the date was less than 91 days; a yellow dot for 91-180 days, and a red dot for 181+ days.

datediff() calculates date intervals of seconds, minutes, hours, days, weeks, months or years. I used the days. Sample code follows:


<cfset days_since_reviewed = #datediff("d",reviewed_date,dateformat(now(),'mm/dd/yyyy'))#>
<cfif #days_since_reviewed# gt 180>
<cfset reviewed_image="red_dot.gif">
<cfelseif #days_since_reviewed# gt 90 AND #days_since_reviewed# lt 181>
<cfset reviewed_image="yellow_dot.gif">
<cfelseif #days_since_reviewed# lt 90>
<cfset reviewed_image="green_dot.gif">
</cfif>


Adobe Livedocs

No comments:

Post a Comment

Any anonymous comments with links will be rejected. Please do not comment off-topic