Skip to main content

Python Datetime Range

tests

pydt-range is purely python mini library that allows to iterate over datetime objects with a specified step (similar to built-in range())

Installation

Pip

pip install pydt-range

Poetry

poetry add pydt-range

Usage

With default step

from datetime import datetime

from pydt_range import datetime_range

start_dt = datetime(2022, 1, 1)
end_dt = datetime(2022, 1, 10)

for dt in datetime_range(start_dt, end_dt):  # Default step is timedelta(days=1)
    print(dt)
"""
2022-01-01 00:00:00
2022-01-02 00:00:00
2022-01-03 00:00:00
2022-01-04 00:00:00
2022-01-05 00:00:00
2022-01-06 00:00:00
2022-01-07 00:00:00
2022-01-08 00:00:00
2022-01-09 00:00:00
"""

With custom step

from datetime import datetime
from dateutil.relativedelta import relativedelta

from pydt_range import datetime_range

start_dt = datetime(2022, 1, 1)
end_dt = datetime(2022, 1, 10)
step = relativedelta(hours=6)

for dt in datetime_range(start_dt, end_dt, step):
    print(dt)
"""
2022-01-01 00:00:00
2022-01-01 06:00:00
2022-01-01 12:00:00
2022-01-01 18:00:00
2022-01-02 00:00:00
2022-01-02 06:00:00
2022-01-02 12:00:00
2022-01-02 18:00:00
2022-01-03 00:00:00
2022-01-03 06:00:00
2022-01-03 12:00:00
2022-01-03 18:00:00
2022-01-04 00:00:00
2022-01-04 06:00:00
2022-01-04 12:00:00
2022-01-04 18:00:00
2022-01-05 00:00:00
2022-01-05 06:00:00
2022-01-05 12:00:00
2022-01-05 18:00:00
2022-01-06 00:00:00
2022-01-06 06:00:00
2022-01-06 12:00:00
2022-01-06 18:00:00
2022-01-07 00:00:00
2022-01-07 06:00:00
2022-01-07 12:00:00
2022-01-07 18:00:00
2022-01-08 00:00:00
2022-01-08 06:00:00
2022-01-08 12:00:00
2022-01-08 18:00:00
2022-01-09 00:00:00
2022-01-09 06:00:00
2022-01-09 12:00:00
2022-01-09 18:00:00
"""

Release files for pydt-range 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydt-range 1.1.0
File Size Uploaded
pydt-range-1.1.0.tar.gz 2.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydt-range 1.1.0
File Interpreter ABI Platform
pydt_range-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 5.4 kB

Release files / pydt-range-1.1.0.tar.gz

Download URL pydt-range-1.1.0.tar.gz
Size 2.7 kB
Tags Source
SHA-256 checksum
How to use checksums
96ae2dcbf6a0b8186adf01cfe90591e0460944dba99acfdecb572409d0a8eed6
BLAKE2b-256 checksum
How to use checksums
8824d7c0b9e22cf1f0bb385be958599443c512728107f574a7fa5d74d37610ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.7.12 Linux/5.15.0-58-generic

Release files / pydt_range-1.1.0-py3-none-any.whl

Download URL pydt_range-1.1.0-py3-none-any.whl
Size 2.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e6e67a78c26f11d757f81013f0dc5aa9224f29da536ae65b07b986b64673daee
BLAKE2b-256 checksum
How to use checksums
01baf6ffe1fce95fd4606d65c046458629c32033de68c2a1e81860d53722a5df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.13 CPython/3.7.12 Linux/5.15.0-58-generic

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page