Python Datetime Subtract Days: How to Subtract Days from a Date

A Columbus appliance store asked me for a Python script that emails customers 14 days before their warranty renews. Each row needed one thing: subtract days from a date.

The obvious due - 14 raises a TypeError, and hand counting breaks at month ends.

Quick answer: subtract a timedelta. date(2026, 3, 2) - timedelta(days=14) returns 2026-02-16, and month and year boundaries are handled for you.

from datetime import date, timedelta

date(2026, 3, 2) - timedelta(days=14)   # datetime.date(2026, 2, 16)

In this tutorial, I’ll show how to subtract days from a date in Python for plain dates, datetimes, strings, business days and pandas columns. I ran every example in Python 3.12.5.

Subtract Days from a Date in Python with timedelta

A timedelta is a length of time. Subtract it from a date or datetime and you get a new object back:

from datetime import date, datetime, timedelta

due = date(2026, 3, 2)
print(due - timedelta(days=14))       # crosses into February
print(due - timedelta(days=1))
print(due + timedelta(days=-30))      # same as minus 30

stamp = datetime(2026, 3, 2, 9, 30)
print(stamp - timedelta(days=2, hours=12))

Output:

2026-02-16
2026-03-01
2026-01-31
2026-02-27 21:30:00
Python datetime subtract days: Command Prompt output of date and datetime minus timedelta values
March 2, 2026 minus 14 days lands on February 16, and the datetime keeps its time of day.

A negative timedelta added works the same. To check the new weekday, see getting the day of the week from a date in Python.

Python Current Date Minus 1 Day: Yesterday’s Date

For the current date minus 1 day, start from date.today(). Use datetime.now() when you want exactly 24 hours ago:

from datetime import date, datetime, timedelta

yesterday = date.today() - timedelta(days=1)
print("Yesterday:   ", yesterday)
now = datetime.now().replace(microsecond=0)
print("24 hours ago:", now - timedelta(days=1))

Output:

Yesterday:    2026-11-26
24 hours ago: 2026-11-26 13:27:34

When I ran it on November 27, 2026, yesterday printed as November 26. More on now() and today() is in getting the current date and time in Python.

Subtract Days from a Date String in Python

The store’s CSV export had dates like 03/05/2026. Parse the string with strptime(), subtract, then format it back:

from datetime import datetime, timedelta

text = "03/05/2026"                       # US month/day/year
due = datetime.strptime(text, "%m/%d/%Y").date()
remind = due - timedelta(days=14)
print(remind.strftime("%m/%d/%Y"))        # back to the same format
print((due - timedelta(days=90)).isoformat())

Output:

02/19/2026
2025-12-05

March 5 minus 14 days is 02/19/2026, and minus 90 days goes back to December 5, 2025. Other text formats are covered in converting a string to a date in Python.

Find a Reminder Date for Every Renewal

The four renewals from the intro live in renewals.py:

# Warranty renewal dates for a Columbus appliance store
RENEWALS = {"Emily Carter": "2026-01-10", "James Miller": "2026-03-05",
            "Olivia Brooks": "2026-07-04", "Noah Davis": "2026-12-01"}
REMIND_DAYS = 14

The loop subtracts REMIND_DAYS from each one:

from datetime import date, timedelta
from renewals import RENEWALS, REMIND_DAYS

for name, text in RENEWALS.items():
    due = date.fromisoformat(text)
    remind = due - timedelta(days=REMIND_DAYS)
    print(f"{name:<14} renews {due:%b %d, %Y}   remind {remind:%b %d, %Y}")

Output:

Emily Carter   renews Jan 10, 2026   remind Dec 27, 2025
James Miller   renews Mar 05, 2026   remind Feb 19, 2026
Olivia Brooks  renews Jul 04, 2026   remind Jun 20, 2026
Noah Davis     renews Dec 01, 2026   remind Nov 17, 2026
Command Prompt output of Python subtracting 14 days from four warranty renewal dates
Emily Carter’s January 10 renewal gets a December 27, 2025 reminder, so the year rolls back on its own.

The year change needed no special case. For month-end renewals, see getting the last day of a month in Python helps you build it.

Subtract Business Days with NumPy busday_offset

The store didn’t want weekend reminders. timedelta counts calendar days, so for business days you can use NumPy 2.5.3 and busday_offset():

import numpy as np

due = np.datetime64("2026-07-06")              # a Monday
print(np.busday_offset(due, -5, roll="backward"))

holidays = ["2026-07-03"]                      # July 4th, observed
print(np.busday_offset(due, -5, roll="backward", holidays=holidays))

Output:

2026-06-29
2026-06-26
Command Prompt output of NumPy busday_offset subtracting five business days with and without a holiday
Five business days before Monday, July 6 is June 29; skipping the July 3 holiday moves it to June 26.

The holidays list skips company days off. The same weekday logic powers getting the week number from a date in Python.

Subtract Days from a pandas Datetime Column

Once the renewals sat in a DataFrame (pandas 3.0.6), one line handled every row. pd.to_timedelta() also takes a different day count per row:

import pandas as pd
from renewals import RENEWALS, REMIND_DAYS

df = pd.DataFrame({"customer": list(RENEWALS),
                   "renews": pd.to_datetime(list(RENEWALS.values()))})
df["remind"] = df["renews"] - pd.Timedelta(days=REMIND_DAYS)
df["lead"] = [7, 14, 30, 60]
df["custom"] = df["renews"] - pd.to_timedelta(df["lead"], unit="D")
print(df)

Output:

        customer     renews     remind  lead     custom
0   Emily Carter 2026-01-10 2025-12-27     7 2026-01-03
1   James Miller 2026-03-05 2026-02-19    14 2026-02-19
2  Olivia Brooks 2026-07-04 2026-06-20    30 2026-06-04
3     Noah Davis 2026-12-01 2026-11-17    60 2026-10-02
Command Prompt output of a pandas DataFrame with renewal dates minus a fixed and a per-row Timedelta
The remind column matches the loop above, and the custom column uses each customer’s own lead time.

Noah Davis’s 60-day lead gives October 2, 2026. Text dates from Excel or a CSV need converting the pandas column to datetime first.

What Happens When You Subtract Two Dates in Python?

Subtracting one date from another doesn’t give a date. It gives a timedelta, and .days pulls out the number:

from datetime import date

renews = date(2026, 3, 5)
today = date(2026, 11, 27)
gap = today - renews
print(gap, "|", gap.days)
print((renews - today).days)

Output:

267 days, 0:00:00 | 267
-267

That’s 267 days, or -267 the other way round. For more, read calculating the number of days between two dates in Python.

Date Subtraction Errors and Their Fixes

These three TypeErrors cover almost every failed Python date subtraction I’ve debugged:

from datetime import date, datetime, timedelta, timezone

due = date(2026, 3, 2)
tests = [("date - 14", lambda: due - 14),
         ("str - timedelta", lambda: "2026-03-02" - timedelta(days=1)),
         ("aware - naive", lambda: datetime.now(timezone.utc)
                                   - datetime(2026, 3, 2))]
for label, fn in tests:
    try:
        fn()
    except TypeError as err:
        print(f"{label}: {err}")

Output:

date - 14: unsupported operand type(s) for -: 'datetime.date' and 'int'
str - timedelta: unsupported operand type(s) for -: 'str' and 'datetime.timedelta'
aware - naive: can't subtract offset-naive and offset-aware datetimes

Wrap the number in timedelta(days=14), parse strings before the math, and keep both datetimes naive or both aware. Naive vs aware datetimes in Python explains that last one.

Still working with Python dates? These pair well with this one:

Questions About Subtracting Days in Python

How do I subtract days from a date in Python?

Subtract a timedelta: d - timedelta(days=7) returns the date a week earlier.

How do I get the current date minus 1 day in Python?

Use date.today() - timedelta(days=1), or datetime.now() - timedelta(days=1) to keep the time.

How do I subtract days from a date string in Python?

Parse it with datetime.strptime(), subtract a timedelta, then format it back with strftime().

How do I subtract months from a date in Python?

Use d - relativedelta(months=1) from dateutil; timedelta has no months.

How do I get the number of days from a timedelta?

Read its .days attribute, for example (d2 - d1).days.

Where is timedelta documented?