Calculate the number of days between two dates.
Code
GeneralMath.abs(Math.floor((new Date(date2) - new Date(date1)) / (1000 * 60 * 60 * 24)));Parameters
First date (YYYY-MM-DD)
Second date (YYYY-MM-DD)
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Add Days to Date
Add a specified number of days to a date and return the result in ISO format.
Business Days Between
Calculate the number of business days (weekdays) between two dates. Excludes Saturdays and Sundays, useful for project planning and SLA calculations.
Calculate Age
Calculate age in years from a birth date, accounting for month and day.
Count Working Days
Count working days (excluding weekends) between dates.
Days in Month
Get the number of days in a specific month.
End of Day
Get the end of day (23:59:59.999) for a date.