ItSolutionStuff.com

Python Get Month Name from Number Example

By Hardik Savani • October 30, 2023
Python

In this tutorial, I will show you python get month name from number. Here you will learn python calendar get month name from number. you will learn how to get month name from number in python. you'll learn python3 find month name from number.

In this example, I will give two examples for you of how to get the month name from number in python. therefore, let's see below example code and try it.

Example 1: using datetime

main.py

import datetime
  
monthNumber = "7"
dateTimeObject = datetime.datetime.strptime(monthNumber, "%m")
  
monthName = dateTimeObject.strftime("%b")
print("Month Short Name: ", monthName)
  
fullMonthName = dateTimeObject.strftime("%B")
print("Month Full Name: ", fullMonthName)

Output:

Month Short Name:  Jul
Month Full Name:  July

Example 2: using calendar

main.py

import calendar
  
monthNumber = 7
  
res = calendar.month_name[monthNumber]
  
print("Month Name : " + str(res))

Output:

Month Name : July

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

How to Get Tomorrow Date in Python?

Read Now →

How to Get Current Second 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 Time in Python?

Read Now →

How to Get Current Month in Python?

Read Now →

How to Get Current Day in Python?

Read Now →

How to Get Current Year in Python?

Read Now →

How to Get Current Date and Time in Python?

Read Now →

How to Get Current Date in Python?

Read Now →