I want to create function which return me the difference between two dates excluding weekends and holidays ?
Eg:- Difference between 01/07/2019 and 08/07/2019 should return me 5 days excluding (weekend on 6/7/107 and 7/07/2019).
What should be best possible way to achieve this ???
Try converting string into date using the format of your date using pd.to_datetime()
use np.busday_count
to find difference between days excluding the weekends
import pandas as pd
import numpy as np
date1 = "01/07/2019"
date2 = "08/07/2019"
date1 = pd.to_datetime(date1,format="%d/%m/%Y").date()
date2 = pd.to_datetime(date2,format="%d/%m/%Y").date()
days = np.busday_count( date1 , date2)
print(days)
5
holidays = pd.to_datetime("04/07/2019",format="%d/%m/%Y").date()
days = np.busday_count( start, end,holidays=[holidays] )
print(days)
4
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With