daterange#

daterange(start_date=None, end_date=None, interval=None, inclusive=True, as_date=None, 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 (see also kwargs below)

  • 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; else, as input type (e.g. strings; note: you can also use “asdate” instead of “as_date”)

  • readformat (str) – passed to sc.date()

  • outformat (str) – passed to sc.date()

  • kwargs (dict) – optionally, use any valid argument to sc.datedelta() to create the end_date

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
New in version 3.0.0: preserve input type