get current month name as str python datetime in python

You can use the strftime method of datetime object to get the name of the current month. Here's an example:

main.py
from datetime import datetime

current_month_name = datetime.now().strftime('%B')
print(current_month_name)
108 chars
5 lines

This will output the name of the current month as a string, such as "January", "February", etc.

The %B is a formatting directive that tells strftime to substitute the full name of the month. If you want to get the abbreviated name (e.g. "Jan", "Feb"), use %b instead.

related categories

gistlibby LogSnag