In this C# program, we will learn how to write a program to compare two dates.
Here is the code of the program to compare two dates:
using System;
namespace Tutorialsrack
{
class Program
{
/* C# Program to Compare Two Dates */
static void Main(string[] args)
{
DateTime start_date = new DateTime(2019, 11, 29);
Console.WriteLine("Start Date : {0}", start_date);
DateTime End_date = start_date.AddDays(10);
Console.WriteLine("End Date : {0}", End_date);
if (start_date < End_date)
{
Console.WriteLine("Start Date: {0} Smaller than End Date: {1}", start_date, End_date);
}
else
{
Console.WriteLine("Start Date: {0} Greater than End Date: {1}", start_date, End_date);
}
Console.ReadKey();
}
}
}
Start Date : 29-11-2019 00:00:00
End Date : 09-12-2019 00:00:00
Start Date: 29-11-2019 00:00:00 Smaller than End Date: 09-12-2019 00:00:00
Comments