Get month name from number Get month name from number python python

Get month name from number


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

Returns: December

Some more info on the Python doc website


[EDIT : great comment from @GiriB] You can also use %b which returns the short notation for month name.

mydate.strftime("%b")

For the example above, it would return Dec.


Calendar API

From that you can see that calendar.month_name[3] would return March, and the array index of 0 is the empty string, so there's no need to worry about zero-indexing either.


import datetimemonthinteger = 4month = datetime.date(1900, monthinteger, 1).strftime('%B')print month

April