Whenever

0.10.0 · active · verified Thu Apr 09

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.

Warnings

Install

Imports

Quickstart

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.

import whenever

# Get the current datetime in the system's local timezone
local_now = whenever.now()
print(f"Local Now: {local_now}")

# Get current UTC datetime
utc_now = whenever.now('UTC')
print(f"UTC Now: {utc_now}")

# Get current datetime in a specific timezone
paris_now = whenever.now('Europe/Paris')
print(f"Paris Now: {paris_now}")

# Create a specific date
my_date = whenever.date(2023, 10, 27)
print(f"My Date: {my_date}")

# Add 2 years and 3 months to a datetime
# Use the new add method with keyword arguments
future_datetime = utc_now.add(years=2, months=3)
print(f"Future Datetime (UTC): {future_datetime}")

# Calculate difference between two datetimes using 'until'
delta = utc_now.until(future_datetime)
print(f"Delta: {delta}")

view raw JSON →