In this article, we will learn how to get a month's name using the date in python.
Example 1: In this example, we will use strftime('%B')
date formatting method from datetime
module to get the full month name using the date.
# Import Module
import datetime
def Month_Name_Using_Date(date):
Month_name=date.strftime('%B')
return Month_name
print ("\nFull Month Name: ",Month_Name_Using_Date(datetime.date(2020,5,3)))
# Output ==> Full Month Name: May
print ("\nFull Month Name: ",Month_Name_Using_Date(datetime.date(2020,2,3)))
# Output ==> Full Month Name: February
Example 2: In this example, we will use strftime('%b')
date formatting method from datetime
module to get the short month name or month name abbreviation using Date.
# Import Module
import datetime
def Month_Name_Using_Date(date):
Month_name=date.strftime('%b')
return Month_name
print ("\nShort Month Name: ",Month_Name_Using_Date(datetime.date(2020,5,3)))
# Output ==> Short Month Name: May
print ("\nShort Month Name: ",Month_Name_Using_Date(datetime.date(2020,2,3)))
# Output ==> Short Month Name: Feb
I hope this article will help you to understand how to get a month's name using the date in python.
Share your valuable feedback, please post your comment at the bottom of this article. Thank you!
Comments