pandas.tseries.holiday.previous_workday#
- pandas.tseries.holiday.previous_workday(dt)[source]#
Move to the previous weekday.
The date is always moved back by at least one day, even when
dtalready falls on a weekday. To leave weekdays unchanged and move only weekend dates back, useprevious_friday.- Parameters:
- dtdatetime
The date to move back from.
- Returns:
- datetime
The previous weekday before
dt.
See also
tseries.holiday.next_workdayMove to the next weekday.
tseries.holiday.previous_fridayMove Saturday and Sunday back to the previous Friday.
tseries.holiday.before_nearest_workdayMove to the workday before the nearest workday.
Examples
>>> from datetime import datetime >>> from pandas.tseries.holiday import previous_workday >>> previous_workday(datetime(2022, 1, 2)) # Sunday datetime.datetime(2021, 12, 31, 0, 0) >>> previous_workday(datetime(2022, 1, 5)) # Wednesday, still moves back datetime.datetime(2022, 1, 4, 0, 0)