Home / Date guides / Guide: days between dates

How to Calculate the Days Between Two Dates

Every way to count the days between two dates: by hand, in a spreadsheet, in SQL and in code, with leap years, inclusive counting and time zones explained.

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.

WhereHow
OnlineDays between dates
Excel=B1-A1 or =DATEDIF(A1,B1,"d")
Google Sheets=DAYS(B1,A1) or =B1-A1
Business daysNETWORKDAYS, NETWORKDAYS.INTL
SQLDATEDIFF, or subtracting dates
Python(d2 - d1).days
JavaScriptDifference in UTC milliseconds divided by 86,400,000
PHPDateTime::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

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.

Open the days between dates calculator

Frequently asked questions

How do I calculate the number of days between two dates?

Subtract the earlier date from the later one. In Excel use =B1-A1, and in Python use (d2 - d1).days.

Should I add one day to include both dates?

Yes, if both the first and the last day count. The plain difference does not count the starting day.

How do I count business days in Excel?

Use NETWORKDAYS(start, end, holidays). For a weekend other than Saturday and Sunday, use NETWORKDAYS.INTL.

Why is my result one day off in code?

Daylight saving time can make a day 23 or 25 hours long. Use dates without times, or convert both to UTC before you subtract.