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

We Are Recommending You

Python Create Zip Archive from Directory Example

Read Now →

How to Check if Today is Wednesday or not in Python?

Read Now →

Python Check if Date is Weekend or Weekday Example

Read Now →

Python PATCH Request with Parameters Example

Read Now →

Python GET Request with Parameters Example

Read Now →

How to Subtract Months to Date in Python?

Read Now →

How to Get Tomorrow Date in Python?

Read Now →

How to Get Current Minute in Python?

Read Now →

How to Get Current Hour in Python?

Read Now →

How to Get Current Month in Python?

Read Now →

How to Get Current Year in Python?

Read Now →