w3resource logo
C# Sharp Programming Exercises

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

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.

Sample Solution:-

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);
    }
}

Sample Output:

 Check whether the given year, month and day is the current or not :                                          
------------------------------------------------------------------------                                      
 Input the Day : 12                                                                                           
 Input the Month : 06                                                                                          
 Input the Year : 2017                                                                                        
 The formatted Date is : 12/06/2017                                                                           
 The current date status : True 
 

C# Sharp Code Editor:

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