Program to Convert Days to Year, Month, Week and day

Program to Convert Days to Year, Month, Week and day

  • Write a program to Convert Days to Year, Month, Week and day in C
  • Write a program to Convert Days to Year, Month, Week and day in C++
  • Write a program to Convert Days to Year, Month, Week and day in Python
  • Write a program to Convert Days to Year, Month, Week and day in PHP
  • Write a program to Convert Days to Year, Month, Week and day in Java
  • Write a program to Convert Days to Year, Month, Week and day in Java Script
  • Write a program to Convert Days to Year, Month, Week and day in C#

Explanation:

Use these procedures to change days into years, months, weeks, and days:

Assumptions

  • 1 year = 365 days
  • 1 month = 30 days (approximation)
  • 1 week = 7 days

Steps to Calculate

  1. Divide the total days by 365 to get the number of years.
    • Years = days ÷ 365
  2. Take the remainder from the above step and divide it by 30 to get the number of months.
    • Months = remainder ÷ 30
  3. Take the remainder from the above step and divide it by 7 to get the number of weeks.
    • Weeks = remainder ÷ 7
  4. The final remainder is the remaining number of days.

Program to Convert Days to Year, Month, Week and day

#include <stdio.h>

int main() {
    int days, years, months, weeks, remaining_days;

    // Input total number of days
    printf("Enter number of days: ");
    scanf("%d", &days);

    // Calculate years, months, weeks, and remaining days
    years = days / 365;
    days = days % 365;
    months = days / 30;
    days = days % 30;
    weeks = days / 7;
    remaining_days = days % 7;

    // Output the result
    printf("%d days is equal to %d years, %d months, %d weeks, and %d days.\n", 
            days, years, months, weeks, remaining_days);

    return 0;
}

#include <iostream>
using namespace std;

int main() {
    int days, years, months, weeks, remaining_days;

    // Input total number of days
    cout << "Enter number of days: ";
    cin >> days;

    // Calculate years, months, weeks, and remaining days
    years = days / 365;
    days = days % 365;
    months = days / 30;
    days = days % 30;
    weeks = days / 7;
    remaining_days = days % 7;

    // Output the result
    cout << days << " days is equal to " << years << " years, " << months << " months, "
         << weeks << " weeks, and " << remaining_days << " days." << endl;

    return 0;
}

days = int(input("Enter number of days: "))

# Calculate years, months, weeks, and remaining days
years = days // 365
days = days % 365
months = days // 30
days = days % 30
weeks = days // 7
remaining_days = days % 7

# Output the result
print(f"{days} days is equal to {years} years, {months} months, {weeks} weeks, and {remaining_days} days.")

<?php
// Input total number of days
$days = (int)readline("Enter number of days: ");

// Calculate years, months, weeks, and remaining days
$years = intdiv($days, 365);
$days = $days % 365;
$months = intdiv($days, 30);
$days = $days % 30;
$weeks = intdiv($days, 7);
$remaining_days = $days % 7;

// Output the result
echo "$days days is equal to $years years, $months months, $weeks weeks, and $remaining_days days.\n";
?>

import java.util.Scanner;

public class DaysToYearsMonthsWeeksDays {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // Input total number of days
        System.out.print("Enter number of days: ");
        int days = scanner.nextInt();

        // Calculate years, months, weeks, and remaining days
        int years = days / 365;
        days = days % 365;
        int months = days / 30;
        days = days % 30;
        int weeks = days / 7;
        int remaining_days = days % 7;

        // Output the result
        System.out.printf("%d days is equal to %d years, %d months, %d weeks, and %d days.\n", 
                          days, years, months, weeks, remaining_days);

        scanner.close();
    }
}

let days = parseInt(prompt("Enter number of days: "));

// Calculate years, months, weeks, and remaining days
let years = Math.floor(days / 365);
days = days % 365;
let months = Math.floor(days / 30);
days = days % 30;
let weeks = Math.floor(days / 7);
let remaining_days = days % 7;

// Output the result
console.log(`${days} days is equal to ${years} years, ${months} months, ${weeks} weeks, and ${remaining_days} days.`);

using System;

class Program {
    static void Main() {
        // Input total number of days
        Console.Write("Enter number of days: ");
        int days = Convert.ToInt32(Console.ReadLine());

        // Calculate years, months, weeks, and remaining days
        int years = days / 365;
        days = days % 365;
        int months = days / 30;
        days = days % 30;
        int weeks = days / 7;
        int remaining_days = days % 7;

        // Output the result
        Console.WriteLine($"{days} days is equal to {years} years, {months} months, {weeks} weeks, and {remaining_days} days.");
    }
}

List of All Programs