Program to convert given number of days in terms of Years, Weeks and Days Last Updated : 20 Feb, 2023 Comments Improve Suggest changes Like Article Like Report 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. Below is the program implementing above approach: C++ // 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, days 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; cout << "years = " << year; cout << "\nweeks = " << week; cout << "\ndays = " << days; } // Driver Code int main() { int number_of_days = 200; find(number_of_days); return 0; } // This code is contributed by shivanisinghss2110 C // 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, days 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; printf("years = %d",year); printf("\nweeks = %d", week); printf("\ndays = %d ",days); } // Driver Code int main() { int number_of_days = 200; find(number_of_days); return 0; } Java // Java program to convert given // number of days in terms of // Years, Weeks and Days class 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 # Python3 code to convert given # number of days in terms of # Years, Weeks and Days DAYS_IN_WEEK = 7 # Function to find # year, week, days def 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 Code number_of_days = 200 find(number_of_days) # This code contributed #by "Sharad_Bhardwaj" C# // C# program to convert given // number of days in terms of // Years, Weeks and Days using 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 // PHP program to convert // given number of days in // terms of Years, Weeks and Days $DAYS_IN_WEEK = 7; // Function to find // year, week, days function 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. ?> JavaScript <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 Time complexity: O(1)Auxiliary space: O(1) Comment More infoAdvertise with us Next Article Python program to find number of days between two given dates S Shahnawaz_Ali Follow Improve Article Tags : Misc C Programs DSA Basic Coding Problems date-time-program +1 More Practice Tags : Misc Similar Reads Program to calculate the number of odd days in given number of years Given an integer N, the task is to find the number of odd days in the years from 1 to N. Odd Days: Number of odd days refer to those days that are left in a certain year(s) when it's days gets converted into weeks. Say, an ordinary year has 365 days, that is 52 weeks and one odd day. This means, out 7 min read Python program to find number of days between two given dates Finding the number of days between two dates means calculating how much time has passed from one date to another. This is helpful in real-life situations like tracking deadlines, calculating age, planning events or measuring durations in billing and scheduling.Example: Input: dt1 = 01/01/2004, dt2 = 3 min read Python program to find number of days between two given dates Finding the number of days between two dates means calculating how much time has passed from one date to another. This is helpful in real-life situations like tracking deadlines, calculating age, planning events or measuring durations in billing and scheduling.Example: Input: dt1 = 01/01/2004, dt2 = 3 min read Python program to find number of days between two given dates Finding the number of days between two dates means calculating how much time has passed from one date to another. This is helpful in real-life situations like tracking deadlines, calculating age, planning events or measuring durations in billing and scheduling.Example: Input: dt1 = 01/01/2004, dt2 = 3 min read Date after adding given number of days to the given date Given a date and a positive integer x. The task is to find the date after adding x days to the given date Examples: Input : d1 = 14, m1 = 5, y1 = 2017, x = 10Output : d2 = 24, m2 = 5, y2 = 2017 Input : d1 = 14, m1 = 3, y1 = 2015, x = 366Output : d2 = 14, m2 = 3, y2 = 2016 Method 1: 1) Let given date 12 min read Python program to find day of the week for a given date To find the day of the week for a given date, we convert the date into a form that Python can understand and then determine which weekday it falls on. For example, the date "22 02 2003" corresponds to a Saturday.Letâs explore simple and efficient ways to do this.Using Zellerâs CongruenceZellerâs Con 3 min read Like