Program to convert the given number of days in terms of Years, Weeks and Days Using C#

Share Your Love

In this post, we are going to calculate the Years, Weeks and Days by inputting a number of days, which means convert the given number of days in terms of years, weeks and days using C#.

Example Of Days In terms Of Years, Weeks and Days:

Input : 30
Output : years = 0
         week = 4
         days = 2

Input : 20
Output : years = 0
         week = 2
         days = 6

How to solve this Problem?

Step-1: Number of years will be the quotient when a number of days will be divided by 365 i.e days / 365 = years.

Step-2: Number of weeks will be the result of (Number_of_days % 365) / 7.

Step-3: Number of days will be the result of (Number_of_days % 365) % 7.

Below is the program implementing above approach: 

// 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.

Output:

years = 0
weeks = 28
days = 4

Please share and comment on this post and wants to improve WhatsApp us.

Share Your Love
Avatar photo
Lingaraj Senapati

Hey There! I am Lingaraj Senapati, the Founder of lingarajtechhub.com My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.

Articles: 429

Newsletter Updates

Enter your email address below to subscribe to our newsletter