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 2021 CCC Practice Test Hindi Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz