Number of days between two dates:
import datetime
start = datetime.datetime.strptime(raw_input('Enter date in format yyyy,mm,dd : '), '%Y,%m,%d')
end = datetime.datetime.strptime(raw_input('Enter date in format yyyy,mm,dd:'), '%Y,%m,%d')
diff = end-start
print diff.days
>> 361
Getting number of Fridays:
# key 0 would be Monday as the start date is from Monday
days = {
0: 0,
1: 0,
2: 0,
3: 0,
4: 0,
5: 0,
6: 0,
}
full_weeks = (diff.days) / 7
remainder = (diff.days) % 7
first_day = start.weekday() # Start date is on Monday
for day in days.keys():
days[day] = full_weeks
for i in range(0, remainder):
days[(first_day + i) % 7] += 1
print days[4] # Gives number of Fridays between the date range
>> 2
Python docs – Datetime: https://docs.python.org/2/library/datetime.html
2
solved How do I find the number of fridays between two dates(including both the dates) [closed]