Skip to content

Instantly share code, notes, and snippets.

@agmarrugo
Created December 8, 2014 02:38
Show Gist options
  • Save agmarrugo/e74853dd3914513af1d2 to your computer and use it in GitHub Desktop.
Save agmarrugo/e74853dd3914513af1d2 to your computer and use it in GitHub Desktop.
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