Programming Examples

Python function to extract the day month year from given date


Write a Python function which accept the date 'DD-MM-YYYY' format as an argument and return date, month nd year part.

Solution:

def extract_date(date):
    l1=date.split("-")
    return l1[0],l1[1],l1[2]
dt=input("Enter any Date in 'DD-MM-YYYY' format : ")
d,m,y=extract_date(dt)
print("Day Part : ",d)
print("Month Part : ",m)
print("Year Part : ",y)
Output/ Explanation:

Enter any Date in 'DD-MM-YYYY' format : 22-11-2012

Day Part :  22

Month Part :  11

Year Part :  2012

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online MBA 2 years Online MCA Online BCA Best Website and Software Company in Allahabad