Program to convert given number of days in terms of Years, Weeks and Days

30 Jun, 2021
Given number of days, convert it in terms of Years, Week and Days.
Examples : 
Input : 30
Output : years = 0
         week = 4
         days = 2

Input : 20
Output : years = 0
         week = 2
         days = 6
Approach :  
Number of years will be the quotient when number of days will be divided by 365 i.e days / 365 = years.Number of weeks will be the result of (Number_of_days % 365) / 7.Number of days will be the result of (Number_of_days % 365) % 7.
Number of years will be the quotient when number of days will be divided by 365 i.e days / 365 = years.
Number of weeks will be the result of (Number_of_days % 365) / 7.
Number of days will be the result of (Number_of_days % 365) % 7.
Below is the program implementing above approach:  
C++
C
Java
Python3
C#
PHP
Javascript
// C++ program to convert given// number of days in terms of// Years, Weeks and Days#include <bits/stdc++.h>using namespace std; #define DAYS_IN_WEEK 7 // Function to find year,// week, daysvoid find(int number_of_days){    int year, week, days;         // Assume that years is    // of 365 days    year = number_of_days / 365;    week = (number_of_days % 365) /            DAYS_IN_WEEK;    days = (number_of_days % 365) %            DAYS_IN_WEEK;                 cout << "years = " << year;    cout << "\nweeks = " << week;    cout << "\ndays =  " << days;   } // Driver Codeint main(){    int number_of_days = 200;    find(number_of_days);    return 0;} // This code is contributed by shivanisinghss2110
// C program to convert given// number of days in terms of// Years, Weeks and Days#include <stdio.h>#define DAYS_IN_WEEK 7 // Function to find year,// week, daysvoid find(int number_of_days){    int year, week, days;         // Assume that years is    // of 365 days    year = number_of_days / 365;    week = (number_of_days % 365) /            DAYS_IN_WEEK;    days = (number_of_days % 365) %            DAYS_IN_WEEK;    printf("years = %d",year);    printf("\nweeks = %d", week);    printf("\ndays = %d ",days);    } // Driver Codeint main(){    int number_of_days = 200;    find(number_of_days);    return 0;}
// Java program to convert given// number of days in terms of// Years, Weeks and Daysclass GFG{    static final int DAYS_IN_WEEK = 7;         // Function to find year, week, days    static void find(int number_of_days)    {        int year, week, days;                 // Assume that years        // is of 365 days        year = number_of_days / 365;        week = (number_of_days % 365) /                DAYS_IN_WEEK;        days = (number_of_days % 365) %                DAYS_IN_WEEK;                 System.out.println("years = " + year);        System.out.println("weeks = " + week);        System.out.println("days = " + days);    }         // Driver Code    public static void main(String[] args)    {        int number_of_days = 200;        find(number_of_days);    }} // This code is contributed by Azkia Anam.
# Python3 code to convert given# number of days in terms of# Years, Weeks and Days DAYS_IN_WEEK = 7 # Function to find# year, week, daysdef find( number_of_days ):     # Assume that years is    # of 365 days    year = int(number_of_days / 365)    week = int((number_of_days % 365) /                DAYS_IN_WEEK)    days = (number_of_days % 365) % DAYS_IN_WEEK         print("years = ",year,          "\nweeks = ",week,          "\ndays = ",days)     # Driver Codenumber_of_days = 200find(number_of_days) # This code contributed#by "Sharad_Bhardwaj"
// C# program to convert given// number of days in terms of// Years, Weeks and Daysusing System; class GFG{    static int DAYS_IN_WEEK = 7;         // Function to find    // year, week, days    static void find(int number_of_days)    {                 int year, week, days;                 // Assume that years        // is of 365 days        year = number_of_days / 365;        week = (number_of_days % 365) /                DAYS_IN_WEEK;        days = (number_of_days % 365) %                DAYS_IN_WEEK;                 Console.WriteLine("years = " +                           year);        Console.WriteLine("weeks = " +                           week);        Console.WriteLine("days = " +                           days);    }         // Driver Code    public static void Main()    {        int number_of_days = 200;                 find(number_of_days);    }} // This code is contributed by vt_m.
<?php// PHP program to convert// given number of days in// terms of Years, Weeks and Days$DAYS_IN_WEEK = 7; // Function to find// year, week, daysfunction find($number_of_days){    global $DAYS_IN_WEEK;    $year; $week; $days;         // Assume that years    // is of 365 days    $year = (int)($number_of_days / 365);    $week = (int)(($number_of_days % 365) /                   $DAYS_IN_WEEK);    $days = ($number_of_days % 365) %             $DAYS_IN_WEEK;    echo("years = " . $year .         "\nweeks = " . $week .         "\ndays = " . $days);} // Driver Code$number_of_days = 200;find($number_of_days); // This code is contributed by Ajit.?>
<script> // JavaScript program to convert given// number of days in terms of// Years, Weeks and Days      var DAYS_IN_WEEK = 7;     // Function to find year, week, days    function find(number_of_days) {        var year, week, days;         // Assume that years        // is of 365 days        year = parseInt(number_of_days / 365);        week = parseInt((number_of_days % 365) / DAYS_IN_WEEK);        days = (number_of_days % 365) % DAYS_IN_WEEK;         document.write("years = " + year + "<br/>");        document.write("weeks = " + week + "<br/>");        document.write("days = " + days + "<br/>");    }     // Driver Code             var number_of_days = 200;        find(number_of_days); // This code contributed by Rajput-Ji </script>
Output :
years = 0
weeks = 28
days = 4
 
jit_t
Rajput-Ji
shivanisinghss2110
date-time-program
C Programs
School Programming
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
C Program to read contents of Whole File
Producer Consumer Problem in C
Difference between break and continue statement in C
C Hello World Program
Handling multiple clients on server with multithreading using Socket Programming in C/C++
Python Dictionary
Reverse a string in Java
Arrays in C/C++
Introduction To PYTHON
Interfaces in Java