string date = "01/04/2013";
DateTime myDate = DateTime.ParseExact(date, "dd/MM/yyyy",
System.Globalization.CultureInfo.InvariantCulture);
if (myDate > DateTime.Today)
{
Console.WriteLine("greater than");
}
else
{
Console.WriteLine("Less Than");
}
using System;
public class Demo {
public static void Main(){
DateTime d1 = new DateTime(2019, 12, 20, 6, 20, 40);
DateTime d2 = new DateTime(2019, 11, 20, 6, 20, 40);
Console.WriteLine("DateTime 1 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d1);
Console.WriteLine("DateTime 2 = {0:dd} {0:y}, {0:hh}:{0:mm}:{0:ss} ", d2);
int res = DateTime.Compare(d1, d2);
// returns equal to 0 since d1 is equal to d2
Console.WriteLine(res);
}
}
DateTime.Compare(datetime1, datetime2);
/*
datetime1 before datetime2 = -ve
datetime1 equal datetime2 = 0
datetime1 after datetime2 = +ve
*/
var target = DateTime.Parse("3/25/2020");
var todaysDate = DateTime.Today;
if(target > todaysDate)
{
Console.WriteLine("Hello World!");
}
else
{
Console.WriteLine("Too Bad");
}
if(dateTime1.Date == dateTime2.Date)
// or
if (dateTime1.Date.CompareTo(dateTime2.Date))
{
}
if ( DateTime.Parse(date2,CultureInfo.InvariantCulture) <= DateTime.Parse(date1,CultureInfo.InvariantCulture))
{
// perform some code here
}