date_range¶
-
date_range
(begin, end, calendars=(), week_mask=None)[source]¶ Construct a range of dates
- Parameters
begin (
Union
[int
,date
]) – Beginning date or int. An int will be interpreted as the number of business days before end
(which must be a date) :type end:
Union
[int
,date
] :param end: End date or int. An int will be interpreted as the number of business days after begin (which must be a date) :type calendars:Union
[str
,Tuple
[str
, …]] :param calendars: Calendars to use for holidays :type week_mask:Optional
[str
] :param week_mask: Which days are considered weekends (defaults to Saturday and Sunday) :rtype:Iterable
[date
] :return: A generator of dates>>> import datetime as dt >>> today = dt.date.today() >>> dates = tuple(date_range(5, today)) >>> >>> for date in date_range(dt.date(2019, 1, 1), dt.date(2019, 2, 1)): >>> print(date)