Select your cookie preferences

We use essential cookies and similar tools that are necessary to provide our site and services. We use performance cookies to collect anonymous statistics, so we can understand how customers use our site and make improvements. Essential cookies cannot be deactivated, but you can choose “Customize” or “Decline” to decline performance cookies.

If you agree, AWS and approved third parties will also use cookies to provide useful site features, remember your preferences, and display relevant content, including relevant advertising. To accept or decline all non-essential cookies, choose “Accept” or “Decline.” To make more detailed choices, choose “Customize.”

DATE_CMP function

Focus mode
DATE_CMP function - Amazon Redshift

DATE_CMP compares two dates. The function returns 0 if the dates are identical, 1 if date1 is greater, and -1 if date2 is greater.

Syntax

DATE_CMP(date1, date2)

Arguments

date1

A column of data type DATE or an expression that evaluates to a DATE type.

date2

A column of data type DATE or an expression that evaluates to a DATE type.

Return type

INTEGER

Examples

The following query compares the DATE values in the CALDATE column to the date January 4, 2008 and returns whether the value in CALDATE is before (-1), equal to (0), or after (1) January 4, 2008:

select caldate, '2008-01-04', date_cmp(caldate,'2008-01-04') from date order by dateid limit 10; caldate | ?column? | date_cmp -----------+------------+---------- 2008-01-01 | 2008-01-04 | -1 2008-01-02 | 2008-01-04 | -1 2008-01-03 | 2008-01-04 | -1 2008-01-04 | 2008-01-04 | 0 2008-01-05 | 2008-01-04 | 1 2008-01-06 | 2008-01-04 | 1 2008-01-07 | 2008-01-04 | 1 2008-01-08 | 2008-01-04 | 1 2008-01-09 | 2008-01-04 | 1 2008-01-10 | 2008-01-04 | 1 (10 rows)

On this page

PrivacySite termsCookie preferences
© 2025, Amazon Web Services, Inc. or its affiliates. All rights reserved.