Categories
Python Answers

How to get month name from number with Python?

Spread the love

Sometimes, we want to get month name from number with Python.

In this article, we’ll look at how to get month name from number with Python.

How to get month name from number with Python?

To get month name from number with Python, we can use the strftime mehtod.

For instance, we write

import datetime
mydate = datetime.datetime.now()
m = mydate.strftime("%B")

to call datetime.datetime.now to get the current datetime.

Then we call mydate.strftime with '%B' to return a string with the full month name of the current datetime.

Conclusion

To get month name from number with Python, we can use the strftime mehtod.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *