Function Reference > Functions > DATE_COMPARE
  

DATE_COMPARE

Returns an integer indicating which of two dates is earlier. DATE_COMPARE returns an integer value rather than a date value.

Syntax

DATE_COMPARE( date1, date2 )
Argument
Required/
Optional
Description
date1
Required
Date/Time datatype. The first date you want to compare. You can enter any valid expression as long as it evaluates to a date.
date2
Required
Date/Time datatype. The second date you want to compare. You can enter any valid expression as long as it evaluates to a date.

Return Value

-1 if the first date is earlier.
0 if the two dates are equal.
1 if the second date is earlier.
NULL if one of the date values is NULL.

Example

The following expression compares each date in the DATE_PROMISED and DATE_SHIPPED columns, and returns an integer indicating which date is earlier:
DATE_COMPARE( DATE_PROMISED, DATE_SHIPPED )
DATE_PROMISED
DATE_SHIPPED
RETURN VALUE
Jan 1 1997
Jan 13 1997
-1
Feb 1 1997
Feb 1 1997
0
Dec 22 1997
Dec 15 1997
1
Feb 29 1996
Apr 12 1996
-1  (Leap year)
NULL
Jan 6 1997
NULL
Jan 13 1997
NULL
NULL