Get First Date of Last Month in Python

19-Sep-2022

.

Admin

Get First Date of Last Month in Python

Hi Dev,

In this quick example, let's see Get First Date of Last Month in Python. This tutorial will give you simple example of Get Last Month Date in Python. We will use Get Previous Month First Date in Python. Here you will learn 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.

so let's see following examples with output:

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-08-01

#Python