w3resource logo


C# Sharp Programming Exercises

C# Sharp Exercises: Check whether the given year, month and day are the current or not

Secondary Nav

C# Sharp DateTime : Exercise-43 with Solution

Write a program in C# Sharp to check whether the given year, month and day are the current or not.

Test Data :

Input the Day : 17
Input the Month : 09
Input the Year : 2016

Expected Output :

 The formatted Date is : 17/09/2016
 The current date status : True 

C# Sharp Code:

using System;

class dttimeex43
{
    static void Main()
    {
    int yr, mn, dt;
    
    Console.Write("\n\n Check whether the given year, month and day is the current or not :\n");
	Console.Write("------------------------------------------------------------------------\n");
	
    Console.Write(" Input the Day : ");
    dt = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Month : ");
    mn = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Year : ");
    yr = Convert.ToInt32(Console.ReadLine());		
	DateTime value = new DateTime(yr, mn, dt);
	Console.WriteLine(" The formatted Date is : {0}",value.ToString("dd/MM/yyyy"));
	Console.WriteLine(" The current date status : {0}\n",value == DateTime.Today);
    }
}

C# Sharp Practice online:

using System;

class dttimeex43
{
    static void Main()
    {
    int yr, mn, dt;
    
    Console.Write("\n\n Check whether the given year, month and day is the current or not :\n");
	Console.Write("------------------------------------------------------------------------\n");
	
    Console.Write(" Input the Day : ");
    dt = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Month : ");
    mn = Convert.ToInt32(Console.ReadLine());	
    Console.Write(" Input the Year : ");
    yr = Convert.ToInt32(Console.ReadLine());		
	DateTime value = new DateTime(yr, mn, dt);
	Console.WriteLine(" The formatted Date is : {0}",value.ToString("dd/MM/yyyy"));
	Console.WriteLine(" The current date status : {0}\n",value == DateTime.Today);
    }
}

Improve this sample solution and post your code through Disqus.



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program