« Back to Index

Python calculate difference in dates

View original Gist on GitHub

Python calculate difference in dates.py

published = '1466625902'
then = datetime.fromtimestamp(int(published))
now = datetime.now()
elapsed = now - then
minutes = floor(elapsed.seconds / 60)
hours = floor(minutes / 60)

return '{} days and {} hours ago'.format(elapsed.days, hours)