Last active
December 11, 2015 23:29
-
-
Save urschrei/4677383 to your computer and use it in GitHub Desktop.
Number of days and number of months between two dates
This file contains hidden or 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/env python | |
# -*- coding: utf-8 -*- | |
""" | |
Return the number of days between today, and the input date | |
Also calculate how many times the month rolls over | |
The expected format is dd/mm/yyyy | |
There's no input or bounds checking hahahahahahahaha | |
""" | |
import datetime | |
from datetime import date | |
inp = date( | |
*[int(elem) for elem in | |
raw_input("Enter a date in the format dd/mm/yyyy: ").split("/")][::-1]) | |
today = date.today() | |
days = (inp - date.today()).days | |
# establish how many months occur in the date range, excluding current month | |
months = len([ | |
datetime.datetime(year=today.year, month=mn, day=1) for | |
mn in range(today.month, inp.month)]) | |
print("There are %s days between today and %s.") % ( | |
days, inp.strftime("%d/%m/%Y")) | |
print("The first of the month will occur %s times." % months) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment