ExCellerate.Functions.DateTime.Datedif (excellerate v0.4.0)

Copy Markdown View Source

Calculates the signed difference between two dates in the specified unit.

Returns the integer date2 − date1 expressed in the given unit. The result is positive when date2 > date1 and negative when date1 > date2. Use abs() to obtain an unsigned value.

Accepts Date, NaiveDateTime, or DateTime structs for both arguments. When mixing types, Date values are treated as midnight (00:00:00).

Units

  • "years" — complete calendar years between the two dates
  • "months" — complete calendar months between the two dates
  • "days" — total days (truncated toward zero for sub-day precision)
  • "hours" — total hours (truncated toward zero)
  • "minutes" — total minutes (truncated toward zero)
  • "seconds" — total seconds
  • "milliseconds" — total milliseconds

Examples

datedif(date(2024, 1, 1), date(2024, 3, 1), 'days')      60
datedif(date(2020, 6, 15), date(2024, 6, 15), 'years')   4
datedif(date(2024, 3, 1), date(2024, 1, 1), 'days')      -60
datedif(date(2024, 4, 15), date(2024, 1, 15), 'months')  -3
abs(datedif(date(2024, 3, 1), date(2024, 1, 1), 'days'))  60