sciris.sc_datetime.daterange

daterange(start_date=None, end_date=None, interval=None, inclusive=True, as_date=False, readformat=None, outformat=None, **kwargs)[source]

Return a list of dates from the start date to the end date. To convert a list of days (as integers) to dates, use sc.date() instead.

Note: instead of an end date, can also pass one or more of days, months, weeks, or years, which will be added on to the start date via sc.datedelta().

Parameters
  • start_date (int/str/date) – the starting date, in any format

  • end_date (int/str/date) – the end date, in any format

  • interval (int/str/dict) – if an int, the number of days; if ‘week’, ‘month’, or ‘year’, one of those; if a dict, passed to dt.relativedelta()

  • inclusive (bool) – if True (default), return to end_date inclusive; otherwise, stop the day before

  • as_date (bool) – if True, return a list of datetime.date objects instead of strings (note: you can also use “asdate” instead of “as_date”)

  • readformat (str) – passed to date()

  • outformat (str) – passed to date()

  • days (int) – optional

Examples:

dates1 = sc.daterange('2020-03-01', '2020-04-04')
dates2 = sc.daterange('2020-03-01', '2022-05-01', interval=dict(months=2), asdate=True)
dates3 = sc.daterange('2020-03-01', weeks=5)
New in version 1.0.0.
New in version 1.3.0: “interval” argument
New in version 2.0.0: sc.datedelta() arguments