User Guide
554 Chapter 3: ColdFusion Functions
Enclose string constant dates in quotation marks. If the text contains only numbers (such 1932),
and is not surrounded by quotation marks, ColdFusion interprets it as a date/time object,
resulting in an incorrect value.
Example
<cfif IsDefined("form.value")>
<cfset value = form.value>
</cfif>
<cfif IsDefined("form.type")>
<cfset type = form.type>
</cfif>
<cfif IsDefined("form.date1") and IsDefined("form.date2")>
<cfif IsDate(form.date1) and IsDate(form.date2)>
<p>This example uses DateDiff to determine the difference
in
<cfswitch expression = "#form.type#">
<cfcase value="yyyy">years</cfcase>
<cfcase value="q">quarters</cfcase>
<cfcase value="m">months</cfcase>
<cfcase value="y">days</cfcase>
<cfcase value="d">days</cfcase>
<cfcase value="w">weekdays</cfcase>
<cfcase value="ww">weeks</cfcase>
<cfcase value="h">hours</cfcase>
<cfcase value="n">minutes</cfcase>
<cfcase value="s">seconds</cfcase>
<cfdefaultcase>years</cfdefaultcase>
</cfswitch>
dateparts between date1 and date2.
<cfif DateCompare("#form.date1#","#form.date2#") is not 0>
<p>The difference is <cfoutput>#Abs(DateDiff(type, form.date2,
form.date1))#</cfoutput>
<cfswitch expression = "#form.type#">
<cfcase value="yyyy">years</cfcase>
<cfcase value="q">quarters</cfcase>
<cfcase value="m">months</cfcase>
<cfcase value="y">days</cfcase>
<cfcase value="d">days</cfcase>
<cfcase value="w">weekdays</cfcase>
<cfcase value="ww">weeks</cfcase>
<cfcase value="h">hours</cfcase>
<cfcase value="n">minutes</cfcase>
<cfcase value="s">seconds</cfcase>
<cfdefaultcase>years</cfdefaultcase>
</cfswitch>.
<cfelse>
<p>The two dates are equal! Try changing one of the values ...
</cfif>
<cfelse>