# Number of days between two dates based on a given a calendar

I wanted to calculate the number of trading days between 2 given days. There is a discussion in https://stackoverflow.com/questions/62292979/using-quantlib-in-python-how-do-i-get-the-number-of-days-between-two-dates.

However this considers the day-count convention from the Bond coupon's calculation perspective using something Thirty360().

However I wonder why we dont consider a calendar for such calculation? Is there any way to consider the holiday information as well in the day-count calculation?

• Just curious, is this in the context of Brazilian BUS/252 daycount convention? In markets with history of high inflation, sometimes interest is only accrued on business days, not on holidays and weekends, which is why you need the number of business days (rather than actual calendar days) between two dates using specified holiday calendar. Quanttlib does have a Business252 daycounter, but I don't see a way to ql.Business252().daycount(start,end,sao paolo) Sep 19, 2020 at 14:56
• Not really. I was investigating about a general day counter between 2 days for QuantLib's Date class, and wondering how and why that calculation cant take the calendar information. But, Brazilian BUS/252 is equally interesting anyway.. Sep 19, 2020 at 15:07
• The "number of business days" calculation is needed inside BUS/252. have you tried the businessDaysBetween method? rkapl123.github.io/QLAnnotatedSource/da/d3e/… Sep 19, 2020 at 15:11

## 1 Answer

If you want the number of business days acording to a calendar, you can use the businessDaysBetween method from the calendar object, like this:

import QuantLib as ql
d1 = ql.Date(15,3,2020)
d2 = ql.Date(15,6,2020)
cal = ql.TARGET()
days = cal.businessDaysBetween(d1, d2)
print(days)


62

• Thanks. Is it also possible to get the vector of business days between the 2 given dates based on applicable calendar? Sep 19, 2020 at 16:32
• Yes, that would be cal.businessDayList(d1, d2) Sep 19, 2020 at 17:24