Skip to content

Instantly share code, notes, and snippets.

@tincho
Created December 29, 2016 15:21
Show Gist options
  • Save tincho/86af8614b233bca439916d5e021f23f8 to your computer and use it in GitHub Desktop.
Save tincho/86af8614b233bca439916d5e021f23f8 to your computer and use it in GitHub Desktop.
days between two dates
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
import sys
def compare(dates):
if len(dates) < 2:
dto = datetime.date.today()
else:
d, m, y = dates[1].split('/')
dto = datetime.date(int(y), int(m), int(d))
d, m, y = dates[0].split('/')
dfrom = datetime.date(int(y), int(m), int(d))
diff = (dfrom - dto).days
return diff
try:
diff = compare(sys.argv[1:])
if diff < 0:
format = "hace %d días"
else:
format = "en %d días"
print format % abs(diff)
except:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment