Skip to content

Return string from date relative to now

License

Notifications You must be signed in to change notification settings

djlint/RelativeToNow

Folders and files

NameName
Last commit message
Last commit date
Dec 10, 2023
Apr 7, 2022
Jul 29, 2021
Apr 22, 2021
Jan 16, 2023
Mar 6, 2023
Mar 6, 2023
Apr 25, 2022
Jan 18, 2021
Jan 16, 2023
Jul 18, 2022
Oct 8, 2024
Dec 10, 2023
Mar 6, 2023
Jan 16, 2023
Mar 27, 2023
Jan 16, 2023

Repository files navigation

Relative To Now

Convert date/time into a string relative to now.

Python Version Codecov Status Codacy Status Pypi Download Downloads

💾 Install

python -m pip install relative-to-now

# or

poetry add relative-to-now

✨ How to Use

Possible input types:

  • time.time()
  • datetime.date.today()
  • datetime.datetime.now()

Optional inputs:

  • no_errors (Defaults to False, set to True to return value when there is an error instead of raising)

Output:

Examples:

import datetime
from RelativeToNow import relative_to_now

print(relative_to_now(datetime.datetime.now() + datetime.timedelta(days=1)))
>>> 1 day from now

Precision for datetime.date is days.

import datetime
from RelativeToNow import relative_to_now

print(relative_to_now(datetime.date.today() - datetime.timedelta(days=2)))
>>> 2 days ago
import time
from RelativeToNow import relative_to_now

print(relative_to_now(time.time()))
>>> just now