Skip to content

Instantly share code, notes, and snippets.

@thombashi
Created March 6, 2016 11:54
Show Gist options
  • Save thombashi/62cc7e921db01b223839 to your computer and use it in GitHub Desktop.
Save thombashi/62cc7e921db01b223839 to your computer and use it in GitHub Desktop.
Get working days between two dates
#!/usr/bin/env python
# encoding: utf-8
import datetime
import sys
from workalendar.asia import Japan
def get_total_working_day(cal, start_date, end_date):
current_date = start_date
working_days = 0
while current_date < end_date:
if cal.is_working_day(current_date):
working_days += 1
current_date += datetime.timedelta(days=1)
return working_days
def main():
cal = Japan()
print get_total_working_day(
cal, datetime.date(2016, 3, 6), datetime.date(2016, 3, 13))
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment