How to Get Month Name from Number in Python?

Published On: 02/09/2022 | Category: Python


Hi Guys,

Now, let's see example of python number to month name. we will help you to give example of python calendar get month name from number. you will learn how to get month name from number in python. I explained simply about python3 find month name from number.

Here, 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.

So let's see bellow example:

Example 1: main.py
import datetime
  
monthNumber = "9"
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:  Sep
Month Full Name:  September
Example 2: main.py
import calendar
  
monthNumber = 9
  
res = calendar.month_name[monthNumber]
  
print("Month Name : " + str(res))
Output:
Month Name : September

It will help you....