I despise using the ColdFusion DateCompare() and DateDiff() functions. They just don't seem to be very logical to me, or at least I can never remember the exact syntax and output I want. For instance, when I do a DateDiff(), does a negative result mean that the first or second date is later? In addition, the DateCompare() function returns 3 values (-1, 0, or 1), so if I want to compare the dates in an cfif statement, I can't use short-circuit syntax because. Many other CF functions (Pos(), Find(), etc.) allow a short-circuit for a true value because it returns a positive integer while the false value returns a zero.
Because of this, I prefer using the underlying java date functions. A ColdFusion datetime object is a java.util.Date under the covers, which gives you power beyond the normal built-in CF functions. The two Date functions that I use most are date.before() and date.after(), both of which return a boolean result. So, given a CF date object named "mydate", I can easily do a comparison with another date, such as now(). For instance, if the date is in the past, "mydate.before(now())" will return true.
But, before you jump on the horse, you have to remember that CF is loosely typed. So you cannot just do this:
<cfset mydate="1/1/2007">
<cfif mydate.before(now())>
<cfoutput>mydate is in the past</cfoutput>
<cfelse>
<cfoutput>mydate is in the future</cfoutput>
</cfif>
ColdFusion will throw an error stating "The selected method before was not found..." This is because you are operating on a java String, not a Date.
Therefore, you must convert the string to a Date object. You could do this with the CF CreateDate() function, but you would then have to split the month, day, and year out because of the required arguments of that function. A shorter way that doesn't require you to do that is to use the DateAdd() function. You can add a zero value to the date string, and ColdFusion with return a real date object. So change the code to this to make the before() function work:
<cfset mydate=DateAdd("d", 0, "1/1/2007")>
<cfif mydate.before(now())>
<cfoutput>mydate is in the past</cfoutput>
<cfelse>
<cfoutput>mydate is in the future</cfoutput>
</cfif>
You could make it even shorter by bypassing the mydate assignment if you don't need the variable:
<cfif DateAdd("d", 0, "1/1/2007").before(now())>
...
Viola!