Created
December 29, 2016 15:21
-
-
Save tincho/86af8614b233bca439916d5e021f23f8 to your computer and use it in GitHub Desktop.
days between two dates
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/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