Create a gist now

Instantly share code, notes, and snippets.

ago.py
#!/usr/bin/python
from datetime import date
import sys
now = date.today()
inputDate= sys.argv[1].split()
day = int(inputDate[0])
month = int(inputDate[1])
#day = int(sys.argv[1])
#month = int(sys.argv[2])
try:
#year = int(sys.argv[3])
year = int(inputDate[2])
if 50 <= year < 100: # assume 20th century
year += 1900
if 0 <= year < 50: # assume 21st century
year += 2000
except IndexError: # assume this year
year = now.year
then = date(year, month, day)
ago = now - then
print ago.days,'days'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment