Calculation Number Of Days

Instant date span, business days & live distribution

Python Date Difference Calculator

Generate datetime code for date subtraction.

Result
—

How the Python Date Difference Calculator Works

Pick two dates. Copy the Python code and run it. It uses datetime.date values and subtracts the first date from the last one to find the gap in days.

  1. Enter the start date

    Enter the earlier date.

  2. Enter the end date

    Enter the later date.

  3. Generate the snippet

    The calculator writes code with date.fromisoformat().

  4. Run the code

    Run the snippet in Python 3.7 or later. The output is the day count.

How the Count Is Calculated

Python subtracts dates and returns a timedelta object.

from datetime import date
delta = date.fromisoformat(end) - date.fromisoformat(start)
days = delta.days
date
Calendar date with no time or time zone.
timedelta
Duration object returned by subtraction.
.days
Whole days of the timedelta. Negative, if end is earlier.

Example: date(2026, 12, 25) − date(2026, 12, 4) returns timedelta(days=21). (d2 − d1).days returns 21.

Worked Examples

The table lists Python patterns for common date questions.

GoalPython codeResult
Days between dates(d2 - d1).days21
Add daysd1 + timedelta(days=30)date(2027, 1, 3)
Business daysnumpy.busday_count(d1, d2)15
Weekdayd1.weekday() # Monday = 04 (Friday)
Years, months, daysrelativedelta(d2, d1) # dateutilrelativedelta(days=+21)
Seconds between datetimes(t2 - t1).total_seconds()float

What the Tool Measures

Generate Python code to count the days between two dates. Copy the code into your own script to run the same count.

Python’s datetime module handles leap years and month lengths. numpy.busday_count counts weekdays from the start date up to, but not including, the end date, so 4 to 25 December 2026 returns 15.

When to Use This Tool

There are 4 main uses of the Python Date Difference Calculator, including data analysis and scripts.

  • Data analysis

    Analysts compute day gaps in pandas with (df.end - df.start).dt.days.

  • Automation scripts

    Developers schedule reminders a set number of days ahead.

  • Coding interviews

    Candidates practise date math with the standard library.

  • Teaching

    Teachers show how timedelta works.