C#: How to compare two dates

c#, datetime

Solution

You can use `DateTime.Compare` for this:

var result = DateTime.Compare(Convert.ToDateTime(TextBox1.Text), DateTime.Today);
string relationship;

if (result < 0)
   relationship = "is earlier than";
else if (result == 0)
   relationship = "is the same time as";         
else
   relationship = "is later than";

Console.WriteLine("{0} {1} {2}", date1, relationship, date2);

See the documentation on MSDN for more details.

Problem

I want to compare a date stored in a table in the form `DD/MM/YYYY` with the current date. I need to know if it is earlier or later than `DateTime.Now` ... Does someone have an idea to suggest? Thank you in advance.

Original source

Related problems