This question is similar to this question about subtracting dates with Python, but not identical. I\'m not dealing with strings, I have to figure out the difference between
A little improvement over @Schnouki's solution with a single line list comprehension. Also displays the plural in case of plural entities (like hours)
Import relativedelta
>>> from dateutil.relativedelta import relativedelta
A lambda function
>>> attrs = ['years', 'months', 'days', 'hours', 'minutes', 'seconds']
>>> human_readable = lambda delta: ['%d %s' % (getattr(delta, attr), attr if getattr(delta, attr) > 1 else attr[:-1])
... for attr in attrs if getattr(delta, attr)]
Example usage:
>>> human_readable(relativedelta(minutes=125))
['2 hours', '5 minutes']
>>> human_readable(relativedelta(hours=(24 * 365) + 1))
['365 days', '1 hour']