Whenever is a modern datetime library for Python, aiming to provide an intuitive and consistent API for working with dates and times, with a focus on correctness and ease of use. It is currently at version 0.10.0 and has an active development cadence with regular releases.
pip install wheneverVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to get current datetimes in the local system timezone or a specified timezone, create a specific date, add durations using the new keyword arguments for flexible delta calculations, and calculate differences between datetimes.
Migrate to `whenever.ItemizedDelta` or `whenever.ItemizedDateDelta`. For simple additions/subtractions, prefer using `add(years=X, months=Y)` methods directly on datetime objects, or `subtract()`.
Replace usages of `SystemDateTime` with `whenever.ZonedDateTime`. For example, `SystemDateTime.now()` becomes `whenever.ZonedDateTime.now()` (or `whenever.now()`), which defaults to the system's local timezone.
Instead of `whenever.now() + whenever.years(1)`, use the more explicit `whenever.now().add(years=1)`. For more complex deltas, use `whenever.ItemizedDelta` directly: `whenever.ItemizedDelta(years=1, months=2)`.
Always use `whenever.ZonedDateTime` for representing specific points in time across different geographic regions or when dealing with DST. Use `LocalDateTime` only when a date and time are sufficient without timezone context, or `OffsetDateTime` for fixed UTC offsets.
pip install whenever
from whenever import Datetime
from whenever import Datetime
d = Datetime.now()
formatted_string = d.to_string('%Y-%m-%d %H:%M:%S')from whenever import Datetime
date_obj = Datetime.from_string('27-10-2023', '%d-%m-%Y')from whenever import Datetime, Zone
date_obj = Datetime.now(zone=Zone.from_name('America/New_York'))