Quick actions

cmd+k|ctrl+k

Navigation

Languages

month_first_last

Snippet info

Language

Python

Visibility

public

Author

complex.alpha.work

Created

2026-06-05T08:34:19.958538Z

Updated

2026-06-05T08:34:41.748723Z

from datetime import date, timedelta
import calendar

today = date.today()

this_month_first = today.replace(day=1)
this_month_first_str = this_month_first.strftime("%Y-%m-%d")

this_month_last_str = today.replace(
    day=calendar.monthrange(today.year, today.month)[1]
).strftime("%Y-%m-%d")

prev_month_last = this_month_first - timedelta(days=1)
prev_month_first = prev_month_last.replace(day=1)

prev_month_first_str = prev_month_first.strftime("%Y-%m-%d")
prev_month_last_str = prev_month_last.strftime("%Y-%m-%d")

print(prev_month_first_str)
print(prev_month_last_str)

print(this_month_first_str)
print(this_month_last_str)
INFO