Days Between
Calculates the number of days between two dates.
Category | Dates |
Author | Polgubau |
Since | 1.0.0 |
Last Updated | 2025-03-17 |
Type | Sync |
Compatibility | Universal |
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
Name | Type | Default | Required | Description |
---|---|---|---|---|
date1 | Date | null | No | The first date to compare. |
date2 | Date | null | No | The 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
- random
- universal
- sync
- Since 1.0.4
- functions
- browser
- sync
- Since 1.0.0
- random
- universal
- sync
- Since 1.0.4
getRandomArrayItem
Get a random item from a given array.
getBrowserInfo
Returns information about the user's browser, including name, version, and user agent string.
pickRandom
Pick a specified number of random items from an array without repeating.