Calculate the difference between two dates or add and subtract years, months, weeks, and days from any date, with leap-year and month-end handling.
Related Calculators
- Notice Period Calculator
- 12 Hours From Now Calculator
- Absolute Age Calculator
- Age In Days Calculator
- All Everyday Life and Education Calculators
- Timestamp Converter: Unix and Windows FILETIME
Date Formula
The following formula is used to calculate the number of days between dates.
- Where D is the number of days in between
- ED is the end date expressed as a calendar-day ordinal
- SD is the start date expressed using the same calendar-day ordinal system
Standard difference subtracts the start dateโs Gregorian calendar-day ordinal from the end dateโs. Inclusive counting adds 1 and counts both dates, so the same date gives 0 days standard or 1 day inclusive. The end date must be on or after the start date.
How do you calculate the number of days between dates?
- Identify the Dates: Determine the start date and the end date you want to calculate the difference between. Ensure you have the year, month, and day for both dates.
- Convert the Dates to Julian Day Numbers (Optional): This step involves converting both dates into a numerical format that represents the number of days since a fixed point in the past, known as the Julian day number. This step is optional and mostly used in astronomical calculations or to simplify the calculation, especially if the dates span multiple years.
- Calculate the Difference for Dates within the Same Year:
- If the dates are within the same year, you can calculate the difference by converting each date into the number of days from the beginning of the year and then subtracting the smaller number from the larger number.
- To convert a date into the number of days from the beginning of the year, use the month and day to reference a standard calendar or a day-of-year chart which accounts for leap years.
- Account for Leap Years: Include February 29 only when it lies in the counted range. Do not add it again when a date ordinal or a 366-day year has already included it. Gregorian leap years divide by 4, except century years must divide by 400.
- Consider Different Years: If the dates span multiple years, calculate the days remaining in the first year, the days in the intervening full years, and the days in the final year up to the end date. Sum these values together.
- For the days remaining in the first year, calculate from the start date to the end of that year.
- For each intervening full year, add 365 days (or 366 for leap years).
- For the final year, calculate the days from the beginning of the year to the end date.
- Sum the Days: Add up the days calculated in the steps above to get the total number of days between the two dates.
- Adjust for Inclusive/Exclusive Counting: Depending on whether you want the count to be inclusive (counting both the start and end dates) or exclusive (not counting one or both of the dates), you might need to add or subtract a day from your total.
In the add/subtract mode, whole years are applied first, then whole months, then weeks and days. Years and months clamp to the last valid day: January 31, 2024 plus one month is February 29, 2024. At least one interval must be greater than zero. Results stay within years 1โ9999. Calendar-day arithmetic does not measure elapsed 24-hour periods, business days, or historical calendar adoption.
