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 [, datePart])

Argument Reference

date1 date

A date to compare

date2 date

Another date to compare

datePart string
Default: s

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



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

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");

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