Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,900 questions

51,831 answers

573 users

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 207 views
1 answer 95 views
1 answer 106 views
1 answer 86 views
1 answer 85 views
2 answers 76 views
1 answer 71 views
...