-1

I have created a function for user to input his birthdate and display some info like month name from his birth date entered, however with following code I am getting month number but I need month name, can anyone help me out here? Thanks!

import calendar
import datetime

def birth_day():
    date = input("Please enter your birthdate in format:'1991,03,15' :")
    birthdate = datetime.datetime.strptime(date, '%Y,%m,%d').weekday()
    print("You were born on:", calendar.day_name[birthdate])
    print("-------------------------")

    birth_sign(date)

def birth_sign(date):
    monthname = datetime.datetime.strptime(date, '%Y,%m,%d').month
    print(monthname)

birth_day()
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

I am not very familiar with the library but the task to get month name would be very easy

month_number = 2
lst1 = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']
month = lst1[month_number-1]
Anshumaan Mishra
  • 1,349
  • 1
  • 4
  • 19
  • Thanks Anshumaan for quick reply, I am aware of this method but just wanted to try if I give any input date how would I get month name from it. Thanks though :) – Akshay Lokhande Feb 06 '22 at 08:05
  • @AkshayLokhande in that case you can check out this link: (https://www.geeksforgeeks.org/python-program-to-get-month-name-from-month-number/#:~:text=Method%20%231%20%3A%20Using%20strftime(),just%20return%20a%20Month%20Name.) – Anshumaan Mishra Feb 06 '22 at 08:08