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

dateCompare 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

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

Fork me on GitHub