MRu MRu - 2 months ago 6
C# Question

How to compare datetime.now with a certain date?

Let's say i have a variable of datetime type; varA = '2016-06-10 12:28:36.697'. What is the best way and how i can compare it with

datetime.now
to make sure the date is the same regardless of the year?

Rob Rob
Answer

It's unclear if you want to include the time part of the DateTime as well, or simply the Day and Month. Uncomment/tweak for your use:

bool AreEqual(DateTime left, DateTime right)
{   
    return left.Day == right.Day && left.Month == right.Month
        // && left.TimeOfDay.Equals(right.TimeOfDay)
    ;
}