Skip to content

Instantly share code, notes, and snippets.

@yuchan
Created May 31, 2014 00:25
Show Gist options
  • Save yuchan/1b5b57b719161d0c9929 to your computer and use it in GitHub Desktop.
Save yuchan/1b5b57b719161d0c9929 to your computer and use it in GitHub Desktop.
#! /usr/bin/env python
import sys
from datetime import datetime
arguments = sys.argv
arg_date = arguments[1]
bd = datetime.strptime(arg_date, "%Y%m%d")
now = datetime.now()
diff = now - bd
delta = diff.days / 365.2425
age = int(delta)
month = int((delta - age) * 12)
nextbirthday = bd.replace(year=(now.year + 1))
nextdelta = nextbirthday - now
nextdiff = nextdelta.days + 1
if nextdiff > 365.2425:
nextbirthday = bd.replace(year=(now.year), month=bd.month)
nextdelta = nextbirthday - now
nextdiff = nextdelta.days + 1
print "You are " + str(age) + " years old and " + str(month) + " months."
print "Next Birthday is after " + str(nextdiff) + " days."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment