Skip to main content

WhenWasThat

Python module for returning a human readable value for the time between two specified datetime objects. Inspired by whenWasThat() function from BMC Discovery.

Properties

Property Details
microseconds Output the total number of microseconds between two datetime objects
seconds Output the total number of seconds between two datetime objects
minutes Output the total number of minutes between two datetime objects
hours Output the total number of hours between two datetime objects
days Output the total number of days between two datetime objects
weeks Output the total number of weeks between two datetime objects
months Output the total number of months between two datetime objects
years Output the total number of years between two datetime objects
natural Output an approximate number of seconds, minutes, hours, days, weeks, months or years between two datetime objects

Usage Examples

Retrieve number of days between two dates

>>> import datetime as dt
>>> from WhenWasThat import when
>>> first_date = dt.datetime(2006, 10, 27, 11, 59, 32, 343001)
>>> last_date = dt.datetime(2016, 9, 30, 20, 21, 43, 561783)
>>> when(first_date,last_date).days
3626.348740958125

Output a natural approximation of the time between two dates

>>> first_date = dt.datetime(2006, 10, 27, 11, 59, 32, 343001)
>>> last_date = dt.datetime(2016, 9, 30, 20, 21, 43, 561783)
>>> when(first_date,last_date).natural
Approximately 9.9 years ago

Last date is not required (module will calculate from datetime.now())

>>> time_then = dt.datetime(2020, 3, 23, 0, 1, 1, 1)
>>> when(time_then).weeks
75.20358385298611
>>> when(time_then).natural
Approximately 17.5 months ago

How many days since the Titanic sunk?

>>> dt.datetime.now()
datetime.datetime(2021, 8, 31, 10, 20, 59, 979468)
>>> titanic = dt.datetime(1912, 4, 15, 2, 20, 0, 0)
>>> print("The Titanic sunk %s days ago." % round(when(titanic).days))
The Titanic sunk 39950 days ago.

Releases

Version Summary Known Issues Fixed
Alpha-0.0.1 Alpha release.
0.1.0 Released to PyPi
0.1.1 Released to PyPI with pytest-based test suite and bug fixes
          |                                |

Metadata

Release files for WhenWasThat 0.1.1

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

Source distribution (sdist)

Source distribution for WhenWasThat 0.1.1
File Size Uploaded
whenwasthat-0.1.1.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for WhenWasThat 0.1.1
File Interpreter ABI Platform
whenwasthat-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.9 kB

Release files / whenwasthat-0.1.1.tar.gz

Download URL whenwasthat-0.1.1.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
072d3831c7de34cafbaf31af7e7477c5b34692a6f9fb0e8a01de8a47271f6aee
BLAKE2b-256 checksum
How to use checksums
dab13ac97e78ffcd43976aa2169f5c543fafe254ca7a07b40b744e3431a6d644
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release files / whenwasthat-0.1.1-py3-none-any.whl

Download URL whenwasthat-0.1.1-py3-none-any.whl
Size 4.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ca213084e5d7bfd3aeaeb55a5791891d23829ae39f1aa504d3a87d6d0cae801
BLAKE2b-256 checksum
How to use checksums
42c5aa855eecddd0cd5a71c35c5b1661438859c8b4d21c89e5412fc85aed3317
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.12

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

3 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