User Guide

Chapter 2: ColdFusion Functions 317
DateCompare
Performs a full date/time comparison of two dates. Returns -1 if date1 is less than
date2; returns 0 if date1 is equal to date2; returns 1 if date1 is greater than date2. See the
description of datePart for information on specifying the precision of the comparison.
See also CreateDateTime and DatePart.
Syntax DateCompare(
date1
,
date2
[,
datePart
])
date1
Date/time object in the period from 100 AD to 9999 AD.
date2
Date/time object in the period from 100 AD to 9999 AD.
datePart
Optional. The precision of the comparison. This parameter can have any of the
following values:
s - precise to the second.
n- precise to the minute.
h- precise to the hour.
d- precise to the day.
m- precise to the month.
yyyy- precise to the year.
By default, precision is to the second.
Usage When passing a date/time value as a string, make sure it is enclosed in quotes.
Otherwise, it is interpreted as a number representation of a date/time object, returning
undesired results.
Years from 0 to 29 are interpreted as 21
st
century values. Years 30 to 99 are interpreted
as 20
th
century values.
Examples <!--- This example shows the use of datecompare --->
<HTML>
<HEAD>
<TITLE>
DateCompare Example
</TITLE>
</HEAD>
<basefont face="Arial, Helvetica" size=2>
<H3>DateCompare Example</H3>