Skip to content

DATEDIF ^v2.6.131

Calculates the difference between two dates or times, in the specified time unit.

js
DATEDIF(start_date, end_date, unit)
DATEDIF(start_date, end_date, unit)

Parameters

  • start_date - The start date or time value.
  • end_date - The end date or time value.
  • unit - The time unit to use for the calculation. Valid values: 'Y', 'M', 'D', 'MD', 'YM', 'YD'.

Examples

js
DATEDIF("2022-04-17", "2022-04-19", "D")
DATEDIF("2022-04-17", "2022-04-19", "D")

Result: 2.0

Note: Calculates the number of days between the start and end dates.

js
DATEDIF(44423, 45033, "D")
DATEDIF(44423, 45033, "D")

Result: 610.0

Note: Calculates the number of days between the start and end dates.

js
DATEDIF(44423, 45033, "M")
DATEDIF(44423, 45033, "M")

Result: 20.0

Note: Calculates the number of months between the start and end dates.

js
DATEDIF(44423, 45033, "Y")
DATEDIF(44423, 45033, "Y")

Result: 1.0

Note: Calculates the number of years between the start and end dates.

js
DATEDIF(44423, 45033, "MD")
DATEDIF(44423, 45033, "MD")

Result: 2.0

Note: Calculates the number of days between the start and end dates, excluding years and months.

js
DATEDIF(44423, 45033, "YM")
DATEDIF(44423, 45033, "YM")

Result: 8.0

Note: Calculates the number of months between the start and end dates, excluding years.

js
DATEDIF(44423, 45033, "YD")
DATEDIF(44423, 45033, "YD")

Result: 245.0

Note: Calculates the number of days between the start and end dates, excluding years and months. Note that this value may be negative if the end date is earlier than the start date.