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.