skillfed

DateTimeRange

DateTimeRange is a Python library to handle a time range. e.g. check whether a time is within the time range, get the intersection of time ranges, truncate a time range, iterate through a time range, and so forth.

datetimerange v2.3.2 331.9K downloads/30d#7,511 on PyPI113
Permissive license MIT License Active released

What it is and what it does

DateTimeRange is a Python library for creating and working with time intervals. It wraps datetime objects into range containers that support standard operations—checking whether a specific time falls within a range, finding overlaps between ranges, computing their union or intersection, and iterating through a range at regular intervals. The library handles timezone-aware datetimes and daylight saving time transitions.

You use it when you need to reason about time spans rather than individual moments: scheduling systems that check availability windows, log analysis that filters events within time bounds, or data pipelines that need to split time series into regular chunks. It depends on python-dateutil for relative date arithmetic and typepy for type validation.

Use it for:

  • Check if a specific timestamp falls within a scheduled maintenance window or business hours range.
  • Find overlapping time slots when merging calendar events or meeting availability.
  • Iterate through a date range in monthly or quarterly steps for reporting or data aggregation.
  • Truncate or split time ranges to align with reporting periods or data collection windows.
  • Compute the intersection of multiple time ranges to find common availability across resources.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

DateTimeRange creates and manipulates time range objects, supporting operations like containment checks, intersections, unions, truncation, and iteration over intervals.

Yes. DateTimeRange is actively maintained, has no known vulnerabilities, minimal dependencies, and solves a concrete problem in datetime handling that the standard library handles awkwardly. Install it if your code frequently reasons about time intervals, overlaps, or iteration across date ranges.

Install

datetimerange on PyPI

pip

pip install datetimerange

uv

uv add datetimerange

poetry

poetry add datetimerange

Installing DateTimeRange

Before you install

Low install friction with just two runtime dependencies (python-dateutil and typepy). Actively maintained with a recent commit on 2026-07-20 and stable production status.

License in practice

MIT License permits commercial and private use with minimal restrictions, making it suitable for most projects without licensing concerns.

Quickstart

pip install DateTimeRange

from datetimerange import DateTimeRange
time_range = DateTimeRange("2015-03-22T10:00:00+0900", "2015-03-22T10:10:00+0900")
print("2015-03-22T10:05:00+0900" in time_range)

Requires Python 3.9 or later.

Package facts

License MIT License (permissive)
Python support supports the current Python release (>=3.9)
Install friction low — pure-Python wheel
Runtime dependencies 2 — python-dateutil, typepy
Maintenance actively maintained — 273 days since the last release
Last repo commit
First released
Downloads 331,852/month — #7,511 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: datetimerange-2.3.2-py3-none-any.whl

Keywords: datetimerange, datetime, time range

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Information TechnologyLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.9Topic :: Software Development :: LibrariesTopic :: Software Development :: Libraries :: Python ModulesTopic :: Text ProcessingTyping :: Typed

Tags

time range operationsdatetime interval handlingcheck if time in rangedatetime intersectioniterate time rangestimezone-aware time spanstime range truncate split
datetime-utilitiestime-interval-logic

More Libraries packages