Eren Süleymanoğlu Eren Süleymanoğlu - 3 months ago 13
Python Question

(Django) how to get month name?

I have a query like below:

today = datetime.datetime.now()
month = today.month
print month


and it outputs:

3


I want to display the month name like "March". What should I do?

Answer

use the datetime string formatting method, e.g.

>>> today.strftime('%B')
'March'

for more info, and a full list of formatting codes, see the python datetime docs