Created
December 16, 2014 04:52
-
-
Save jackgolding/bb2a5431e0a6a815ddc2 to your computer and use it in GitHub Desktop.
Campaign Length Calculator
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
def campaign_month(t1, t2): | |
if t1 > t2: | |
return campaign_month(t2, t1) | |
month_dict = {} | |
if t2.month == t1.month and t2.year == t1.year: | |
month_dict[t2.month] = t2.day - t1.day + 1 | |
else: | |
month_dict[t2.month] = t2.day | |
month_dict[t1.month] = monthrange(t1.year, t1.month)[1] - t1.day + 1 | |
if t2.month - t1.month > 1: | |
for i in range(t1.month + 1, t2.month): | |
month_dict[i] = monthrange(t1.year,i)[1] | |
return month_dict | |
campaign_month(datetime(2014,5,10), datetime(2014,7,18)) | |
#output {5: 22, 6: 30, 7: 18} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Small unused snippet of code to create a directory of number of days in each month between two dates. Years does not work.