The short answer
Subtract the earlier date from the later one. The quickest way is the days between dates calculator. In a spreadsheet, subtract the cells. In code, use a date library and take the difference in days.
| Where | How |
|---|---|
| Online | Days between dates |
| Excel | =B1-A1 or =DATEDIF(A1,B1,"d") |
| Google Sheets | =DAYS(B1,A1) or =B1-A1 |
| Business days | NETWORKDAYS, NETWORKDAYS.INTL |
| SQL | DATEDIFF, or subtracting dates |
| Python | (d2 - d1).days |
| JavaScript | Difference in UTC milliseconds divided by 86,400,000 |
| PHP | DateTime::diff() |
By hand
Count the days left in the first month, add the days of the whole months in between, and add the days of the last month. For 20 January to 10 March in a common year, there are 11 days left in January, 28 in February and 10 in March, which makes 49 days. Remember that February has 29 days in a leap year.
Inclusive or exclusive
The plain difference between two dates does not count the starting day. 1 January to 2 January is 1 day. If both the first and the last day count, add 1. Use the difference for nights and elapsed time, and the inclusive count when every calendar day is used, such as days of leave. State which one you mean when you share a number.
Leap years
A year is a leap year if it is divisible by 4, except for century years, which must be divisible by 400. 2000 and 2024 are leap years, and 1900 and 2100 are not. A leap year has 366 days. Date functions in spreadsheets and libraries already know this, so you only need the rule when counting by hand.
Excel and Google Sheets
=B1-A1 ' days between two dates
=DATEDIF(A1,B1,"d") ' days
=DATEDIF(A1,B1,"m") ' complete months
=DATEDIF(A1,B1,"y") ' complete years
=NETWORKDAYS(A1,B1,holidays) ' business days, both dates included
=NETWORKDAYS.INTL(A1,B1,7) ' Friday and Saturday weekend
=WORKDAY(A1,10,holidays) ' 10 business days after A1
The format of the cell with the result must be General or Number, or Excel shows a date instead of a count. The unit md of DATEDIF is known to give wrong results in some cases, so avoid it.
SQL
-- MySQL
SELECT DATEDIFF('2025-03-10', '2025-01-20');
-- PostgreSQL (date minus date gives an integer number of days)
SELECT DATE '2025-03-10' - DATE '2025-01-20';
-- SQL Server (counts day boundaries crossed)
SELECT DATEDIFF(day, '2025-01-20', '2025-03-10');
JavaScript, Python and PHP
// JavaScript: use UTC so that daylight saving time cannot add or remove an hour
const a = Date.UTC(2025, 0, 20), b = Date.UTC(2025, 2, 10);
const days = Math.round((b - a) / 86400000);
# Python
from datetime import date
days = (date(2025, 3, 10) - date(2025, 1, 20)).days
# Python: weekdays from start up to, but not including, the end date
import numpy as np
np.busday_count("2025-01-20", "2025-03-10")
// PHP
$days = (new DateTime('2025-01-20'))->diff(new DateTime('2025-03-10'))->days;
Time zones and daylight saving
If you subtract two date-times with clock times, a day that has 23 or 25 hours because of daylight saving time can make the result one day off when you divide by 24. Use dates without times, or convert both to UTC first, as in the JavaScript example. The calculators on this site use whole days, so this problem does not arise.
Weeks, months and business days
- Weeks between dates: days divided by 7, with ISO week numbers.
- Months between dates: complete, decimal and 30/360 months.
- Business days and working days: skip weekends and holidays.
- Date difference: years, months and days.
- Days until and days since: counts from today.
Related tools
To work with Unix time, use the timestamp to date converter, and read what Unix time is.
Count the days now. Pick two dates and get the number of days, weeks and months.