Documentation

datetime.next

Return a datetime set to be the most recent succeeding specified weekday. For example, calling this function with day_of_week='monday' with a dt of a Friday, it will return the date of the following Monday. If called on Monday with day_of_week='monday', it will return the Monday of the next week.

Times are stripped from the input datetime.

Arguments:

def datetime.next(
  dt: <datetime> = None,
  day_of_week: <str> = None, # 'monday', 'tuesday', ...
):

Returns <datetime>.

Example:


friday_in_january = datetime.from_date_and_time(
  year=2021,
  month=1,
  day=8,
  hour=0,
  minute=0,
  second=0)
  
# monday_in_january == Monday January 11 2021 00:00:00
monday_in_january = datetime.next(dt=friday_in_january,
  day_of_week='monday')