How to get the month name from a date in Python

3 Answers

0 votes
from datetime import datetime

date_str = "2025-01-07"
date_obj = datetime.strptime(date_str, "%Y-%m-%d")

month_name = date_obj.strftime("%B")
print(month_name)

  
  
'''
run:
  
January
  
'''

 



answered Jan 7, 2025 by avibootz
0 votes
import calendar
from datetime import datetime

date_str = "2025-01-07"
date_obj = datetime.strptime(date_str, "%Y-%m-%d")

month_name = calendar.month_name[date_obj.month]
print(month_name) 

  
  
'''
run:
  
January
  
'''

 



answered Jan 7, 2025 by avibootz
0 votes
import pandas as pd

date_str = "2025-01-07"
date_obj = pd.to_datetime(date_str)


month_name = date_obj.strftime("%B")
print(month_name) 

  
  
'''
run:
  
January
  
'''

 



answered Jan 7, 2025 by avibootz

Related questions

1 answer 236 views
1 answer 108 views
1 answer 120 views
1 answer 102 views
1 answer 99 views
2 answers 99 views
1 answer 84 views
...