ItSolutionStuff.com

Python Get First Date of Last Month Example

By Hardik Savani October 30, 2023
Python

This article goes in detailed on python get last month first day. We will use python get last month date. We will use python get first date of previous month. this example will help you how to get last month first date in python.

In this example, I will give you a simple example of getting the first date of last month using datetime and relativedelta. so let's see a simple example with output.

You can use these examples with python3 (Python 3) version.

Example:

main.py

import datetime
from dateutil import relativedelta
  
today = datetime.date.today()
  
# Getting Last Month First Date
lastMonthDate = today - relativedelta.relativedelta(months=1, day=1)
print(lastMonthDate);

Output:

2022-05-01

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube