Days Between

Calculates the number of days between two dates.

CategoryDates
AuthorPolgubau
Since1.0.0
Last Updated2025-03-17
TypeSync
CompatibilityUniversal

Example

  • Input

    daysBetween(new Date('2025-03-17'), new Date('2025-03-22'))

    Output:

    5
  • Input

    daysBetween(new Date('2025-03-17'), new Date('2025-03-14'))

    Output:

    3

Return

The absolute number of days between the two dates.

Type: number

Props

NameTypeDefaultRequiredDescription
date1DatenullNoThe first date to compare.
date2DatenullNoThe second date to compare.

Notes

This function calculates the absolute difference, so it does not matter which date is earlier.

Tags

  • dates
  • utilities
  • date manipulation

Related