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

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

Day Part :  22

Month Part :  11

Year Part :  2012

CCC Online Test Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Online Exam Quiz O Level NIELIT Study material and Quiz Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Best Website and Software Company in Allahabad Website development Company in Allahabad