Skip to main content

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

Project description

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
"""

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydt-range-1.1.0.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydt_range-1.1.0-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file pydt-range-1.1.0.tar.gz.

File metadata

  • Download URL: pydt-range-1.1.0.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.7.12 Linux/5.15.0-58-generic

File hashes

Hashes for pydt-range-1.1.0.tar.gz
Algorithm Hash digest
SHA256 96ae2dcbf6a0b8186adf01cfe90591e0460944dba99acfdecb572409d0a8eed6
MD5 c3ce944ea561a299cc795bff99156be2
BLAKE2b-256 8824d7c0b9e22cf1f0bb385be958599443c512728107f574a7fa5d74d37610ff

See more details on using hashes here.

File details

Details for the file pydt_range-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydt_range-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.7.12 Linux/5.15.0-58-generic

File hashes

Hashes for pydt_range-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6e67a78c26f11d757f81013f0dc5aa9224f29da536ae65b07b986b64673daee
MD5 b27bce0e7c0577542e46e9006684a222
BLAKE2b-256 01baf6ffe1fce95fd4606d65c046458629c32033de68c2a1e81860d53722a5df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page