Comparing only the Datetime field date in C#

Asked

Viewed 4,659 times

5

I only need to compare 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 code above, I need you to enter if when the date (02/09/2016) is equal in the two objects. In this case it does not enter because the Time of the two objects is different. What should I do ?

2 answers

12


You should take the Date property from Datetime for example

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

4

Browser other questions tagged

You are not signed in. Login or sign up in order to post.