pydit.wrangling.date_time_calculations.first_and_end_of_month

pydit.wrangling.date_time_calculations.first_and_end_of_month(d, return_datetime=True)[source]

Function to return the first and last day of a month

Parameters:
  • d (datetime.date or datetime.datetime or str) – The date to use as reference.

  • return_datetime (bool, optional, default: True) – If True, returns datetime.datetime objects, else datetime.date objects

Returns:

A tuple with the first and last day of the month

Note that when returning datetimes, the last day will have the time set to 23:59:59 if you need something else as the last time, you can adjust it after calling this function. e.g. fom_eom(date(2024, 8, 10))[1].replace(hour=0, minute=0, second=1) to be the very first second of the day of if we want it to be the first second of the following month: fom_eom(date(2024, 8, 10))[1] + timedelta(seconds=1)

Return type:

tuple