Created
May 22, 2011 22:01
-
-
Save sebm/985944 to your computer and use it in GitHub Desktop.
Python script for printing time elapsed since stuff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from datetime import date | |
def how_long_between(dayA, dayB): | |
total_days = (dayA - dayB).days | |
years = total_days / 365 | |
days = total_days % 365 | |
months = days / 31 | |
weeks = days / 7 | |
return \ | |
'%d days: %d years and %d days (%d months, or %d weeks)' \ | |
% (total_days, years, days, months, weeks) | |
people = [ | |
['Barack Obama', 1961, 8, 4], | |
['George W. Bush', 1946, 7, 6] | |
] | |
now = date.today() | |
for person in people: | |
print '%s:\n\t%s' % \ | |
(person[0], how_long_between(now, date(person[1], person[2], person[3] ))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment