Name

DateCompare

Synopsis

                  
                  
                  DateCompare(date1, date2 [, datepart])

Compares two date/time objects. Returns -1 if date1 is less than date2, 0 if both date/time objects are equal, or 1 if date1 is greater than date2. Dates must be in the range AD 100-9999. The precision of the comparison may be limited to a specific part of the date/time object by specifying a value for the optional datepart parameter. Valid attributes for datepart are s (second), n (minute), h (hour), d (day), m (month), and yyyy (year). For information on how ColdFusion MX handles two-digit years, see CreateDate( ). Examples:

<cfoutput>
Compare 04/15/03 and 04/15/03: #DateCompare('04/15/03', '04/15/03')#<br>
Compare 04/15/03 and 04/15/2003: #DateCompare('04/15/03', '04/15/2003')#<br>
Compare 15 Apr 2003 and 4/15/03: #DateCompare('15 Apr 2003', '4/15/03')#<br>
Compare August 15, 2003 and July 4, 2002: 
#DateCompare('August 15, 2003', 'July 4, 2002')#<br>
Compare 19:00:00 and 7pm: #DateCompare('19:00:00', '7pm')#<br>
Compare 6:00 and 7:00: #DateCompare('6:00', '7:00')#<br>
Compare 4/15/2003 and Jan 3, 2003 by year: 
#DateCompare('4/15/2003', 'Jan 3, 2003', 'yyyy')#<br>
Compare 6:59 and 7:38 by minute: #DateCompare('6:59', '7:38', 'n')#
</cfoutput>

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.