Documentation

datetime.end_of

Return a datetime set to be the end of some unit of time given by unit. Acceptable values for unit are "hour", "day", "week", "month", and "year".

If the unit is set to "week", the end of the week is considered Sunday at 11:59 PM.

Arguments:

def datetime.end_of(
  dt: <datetime> = None,
  unit: <str> = None, # 'hour', 'day', 'week', 'month', or 'year'
):

Returns datetime.

Example:

long_long_ago = datetime.from_date_and_time(
  year=1995,
  month=1,
  day=1,
  hour=0,
  minute=0,
  second=0)
  
# end_of_1995 == December 31 1995 23:59:59
end_of_1995 = datetime.end_of(dt=long_long_ago, unit='year')