Python Program to Convert Number of Days to Years, Months & Days

This Python program reads number of days from user and then converts it to number of years, months and days.

Note: while converting given number of days to years, months and days integer division is used. In Python, integer division is done by using // operator.

Python Source Code: Days to Years, Months & Days Conversion


# Python program to convert 
# given number of days to years, months and days

# Reading number of days from user
number_of_days = int(input("Enter number of days: "))

# Calculating years
years = number_of_days // 365

# Calculating months
months = (number_of_days - years *365) // 30

# Calculating days
days = (number_of_days - years * 365 - months*30)

# Displaying results
print("Years = ", years)
print("Months = ", months)
print("Days = ", days)

Output

Enter number of days: 3000
Years =  8
Months =  2
Days =  20