Skip to content

Instantly share code, notes, and snippets.

@monokrome
Created January 3, 2014 21:18
Show Gist options
  • Select an option

  • Save monokrome/8246800 to your computer and use it in GitHub Desktop.

Select an option

Save monokrome/8246800 to your computer and use it in GitHub Desktop.
from dateutil.relativedelta import relativedelta
import datetime
def human_readable(delta):
names = [
'years',
'months',
'days',
'hours',
'minutes',
'seconds'
]
items = []
for name in names:
amount = getattr(delta, name)
if amount > 0:
items.append('{0} {1}'.format(amount, name))
return ' '.join(items)
print(human_delta(relativedelta(datetime.datetime.now(), datetime.datetime(
year=2014,
month=1,
day=12)
)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment