March 06, 2004
coldfusion: date math, days since date

This is actually pretty straightforward but it took me a few minutes to figure it out. This was to check if a dog was 6 months old or so... I padded it a bit, becasue if the dog was "too old," it would prevent a user from continuing. I figured give them a bit more than 6 months, hence 195 days.

Notes:
DateDiff is a function that returns the difference between two dates.
Dogs.birthday is a date, Dogs.name is text, from a db query (duh, huh?).

<cfoutput query="dogs">

#Dogs.name#
<CFIF ( DateDiff("d", Now(), Dogs.birthday ) ) GT 195 >
Older than 6 months ( #DateDiff("d", Now(), Dogs.birthday )# days)

<CFELSE>
Younger than 6 months ( #DateDiff("d", Now(), Dogs.birthday )# days)
</CFIF><BR />

</cfoutput>

More info on DateDiff

Posted by illovich at 05:39 PM