dateCompare

Performs a full date/time comparison of two dates.
-1 if date1 is less than date2
0 if date1 is equal to date2
1 if date1 is greater than date2
[DatePart] yyyy: Year; m: Month; d: Day; h: Hour; n: Minute; s: Second

dateCompare(date1, date2 [, datePart]) → returns numeric

Member Function Syntax

date1.compare(date2 [, datePart])

Argument Reference

date1 date
Required

A date to compare

date2 date
Required

Another date to compare

datePart string
Default: s

Values:
  • yyyy
  • m
  • y
  • d
  • h
  • n
  • s

Compatibility

Lucee:

In Lucee "y" can be used instead of "yyyy"

Examples
Sample code invoking the dateCompare function

dateCompare('12/30/2015', '12/02/2015', 'yyyy')

Expected Result: 0

Returns 1 because date1 is greater than date 2

dateCompare('12/30/2015', '12/02/2015', 'd')

Expected Result: 1

d1 = createDate("2024","01","01");
d2 = createDate("2024","02","14");
d1.compare(d2)

Expected Result: -1

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub