DateCompare() - compare two date time object
DateCompare.cfm
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>DateCompare function example: how to compare two date time object</title>
</head>
<body>
<h2 style="color:hotpink">DateCompare Function Example</h2>
<cfset MyDate="3-Dec-2008">
<cfset MyAnotherDate="5-Dec-2008">
<cfoutput>
<b>
MyDate: #MyDate#
<br />
MyAnotherDate: #MyAnotherDate#
</b><br />
</cfoutput>
<cfset DateCompareResult=DateCompare(myDate,MyAnotherDate)>
<cfif DateCompareResult EQ 0>
Two date is same
<cfelseif DateCompareResult LT 0>
MyDate is earlier than MyAnotherDate
<cfelse>
MyDate is later than MyAnotherDate
</cfif>
<br /><br />
<cfset MyDate="8-Dec-2008">
<cfset MyAnotherDate="5-Dec-2008">
<cfoutput>
<b>
MyDate: #MyDate#
<br />
MyAnotherDate: #MyAnotherDate#
</b><br />
</cfoutput>
<cfset DateCompareResult=DateCompare(myDate,MyAnotherDate)>
<cfif DateCompareResult EQ 0>
Two date is same
<cfelseif DateCompareResult LT 0>
MyDate is earlier than MyAnotherDate
<cfelseif DateCompareResult EQ 1>
MyDate is later than MyAnotherDate
</cfif>
</body>
</html>