Comparing only the DateTime field date in C#

I need to compare only the date of two fields DateTime.

DateTime aux = new DateTime(2016, 09, 02, 10, 0, 0);
if (aux.Equals(DateTime.Now))
{
     //Alguma ação...
}

In the above code, I need you to enter if when the date (02/09/2016) is equal on both objects. In this case it does not enter because the Time of the two objects is different. What should I do?

Author: Maniero, 2016-09-02

2 answers

You should take the date property of the DateTime for example

DateTime aux = new DateTime(2016, 09, 02, 10, 0, 0);
if (aux.Date.Equals(DateTime.Now.Date))
{
     //Alguma ação...
}
 12
Author: Marco Giovanni, 2016-11-15 03:03:14

Marco Giovanni's answer is correct, I decided to answer to put the idiomatic Form:

var aux = new DateTime(2016, 09, 02, 10, 0, 0);
if (aux.Date == DateTime.Now.Date) {
    Console.WriteLine("Ok");
}

See working on ideone. And no .NET Fiddle. Also I put on GitHub for future reference .

 4
Author: Maniero, 2020-11-06 21:03:55