How to Calculate the Number of Days Between Two Dates in Python

If you need the number of days between two dates in Python, subtract one date object from the other and read .days on the result. The subtraction returns a timedelta, and .days is an integer.

In this tutorial, I’ll cover four ways to calculate the number of days between two dates in Python, including strings, timestamps and business days. I ran every example on Python 3.12.5 and NumPy 2.5.3.

The Sample Invoice Dates We’ll Use

You’ll reuse three 2026 invoices from a small supply company:

InvoiceCustomerIssuedPaid
INV-2041Emily Carter01/15/202603/02/2026
INV-2042Jacob Miller02/20/202603/23/2026
INV-2043Olivia Brooks03/06/202603/09/2026

INV-2043 spans the March 8 clock change. To shift a date instead of measuring a gap, see subtracting days from a date in Python.

Method 1: Subtract Two date Objects (Recommended)

Use this when you already have date objects. From the same sample invoices, here’s Emily’s INV-2041:

from datetime import date

issued = date(2026, 1, 15)
paid = date(2026, 3, 2)

gap = paid - issued
print(gap, "->", type(gap).__name__)
print("Days to pay:", gap.days)
print("Reversed:", (issued - paid).days)

Output:

46 days, 0:00:00 -> timedelta
Days to pay: 46
Reversed: -46

Emily paid in 46 days.

Command Prompt output of Python subtracting two date objects to get 46 days between them
Subtracting gives a 46-day timedelta; reversing the order gives -46.

How does this code work?

paid - issued builds a timedelta, and .days holds the whole days. Month lengths and leap years are handled for you.

Earlier minus later is negative, so wrap it in abs() if you only want the distance.

For month counts, see counting months between two dates in Python.

Method 2: Find Days Between Date Strings with strptime()

Same three invoices, now as strings:

from datetime import datetime

invoices = [
    ("INV-2041", "Emily Carter", "01/15/2026", "03/02/2026"),
    ("INV-2042", "Jacob Miller", "02/20/2026", "03/23/2026"),
    ("INV-2043", "Olivia Brooks", "03/06/2026", "03/09/2026"),
]
US = "%m/%d/%Y"
for inv, name, issued, paid in invoices:
    d1 = datetime.strptime(issued, US).date()
    d2 = datetime.strptime(paid, US).date()
    print(f"{inv}  {name:<14} {(d2 - d1).days:>3} days")

try:
    datetime.strptime("02/30/2026", US)
except ValueError as err:
    print("ValueError:", err)

Output:

INV-2041  Emily Carter    46 days
INV-2042  Jacob Miller    31 days
INV-2043  Olivia Brooks    3 days
ValueError: day is out of range for month

That gives 46, 31 and 3 days.

Command Prompt output of Python parsing US date strings with strptime and printing days between invoice dates
Each invoice shows its days to pay, and February 30 raises a ValueError.

How does this code work?

%m/%d/%Y tells strptime() the US month/day/year order, and .date() drops the midnight time. ISO strings like 2026-12-31 can use date.fromisoformat() instead.

Important: wrap user input in try. More patterns are in converting a string to a date in Python.

Method 3: Count Days Between datetime Values with Times

Same invoices, now with timestamps. INV-2043 went out Friday afternoon and was paid Monday morning:

from datetime import datetime
from zoneinfo import ZoneInfo

start = datetime(2026, 3, 6, 16, 30)
end = datetime(2026, 3, 9, 9, 15)
gap = end - start
print(gap, "-> .days =", gap.days)
print("Calendar days:", (end.date() - start.date()).days)

ny, utc = ZoneInfo("America/New_York"), ZoneInfo("UTC")
a = datetime(2026, 3, 7, 12, tzinfo=ny)  # DST starts Mar 8
b = datetime(2026, 3, 9, 12, tzinfo=ny)
print("Same zone: ", b - a)
print("Real time: ", b.astimezone(utc) - a.astimezone(utc))

Output:

2 days, 16:45:00 -> .days = 2
Calendar days: 3
Same zone:  2 days, 0:00:00
Real time:  1 day, 23:00:00

.days says 2, but the calendar says 3.

Command Prompt output of Python datetime subtraction showing .days truncation and a DST change with zoneinfo
.days drops the partial day; same-zone math ignores DST.

How does this code work?

.days counts only full 24-hour blocks, so 2 days 16:45 becomes 2. Compare .date() values for calendar days. For a fraction, divide total_seconds() by 86400.

With one shared tzinfo, Python subtracts wall-clock times. UTC shows only 47 real hours passed.

If you mix naive and aware values, you’ll get a TypeError; see naive vs aware datetime in Python.

Method 4: Count Business Days Between Two Dates with NumPy

Same invoices, but terms like “10 business days” skip weekends. NumPy’s busday_count() does that:

import numpy as np

start, end = "2026-05-18", "2026-06-01"
print("Business days:", np.busday_count(start, end))

holidays = ["2026-05-25"]               # Memorial Day
print("Minus holiday:", np.busday_count(start, end, holidays=holidays))

Output:

Business days: 10
Minus holiday: 9

May 18 to June 1, 2026 holds 10 business days, or 9 without Memorial Day.

Command Prompt output of numpy busday_count returning 10 business days and 9 after a Memorial Day holiday
You get ten weekdays in two weeks, and the Memorial Day holiday drops it to nine.

How does this code work?

busday_count() counts weekdays from start up to, but not including, end, minus any holidays.

Run pip install numpy first. For plain-Python weekday logic, see getting the day of the week from a date.

Which Days-Between Method Should You Use?

SituationUse
Two date objects(d2 - d1).days
Date stringsParse with strptime(), then subtract
TimestampsCall .date() first
Weekdays onlynumpy.busday_count()

I’d parse into date objects early and use Method 1.

Things to Keep in Mind When Counting Days Between Dates

  • Subtraction excludes one end; add 1 for an inclusive count.
  • Negative gaps with times round down: -26 hours gives .days == -2.
  • date minus datetime raises TypeError; convert one side first.

These date guides pair well with this one:

Frequently Asked Questions

How do I get the number of days between two dates in Python?

Subtract them and read .days, for example (d2 - d1).days.

How do I count days from today?

Use (target - date.today()).days; negative means it’s past.

Does Python handle leap years?

Yes. You don’t need extra code for February 29.

Why does .days give a smaller number than expected?

It counts only full 24-hour periods. Compare .date() values instead.

How do I include both the start and end date?

Add 1: (end - start).days + 1.

Where is timedelta documented?

See timedelta objects in the Python docs.