ePrivacy and GPDR Cookie Consent by Cookie Consent

On occasion we want to know if two datetimes match on date, ignoring the time component.

Create two datetimes, 10 minutes apart.

var earlierDt = DateTime.Now;// set earlier date to the current datetime
var laterDt = DateTime.Now.AddMinutes(10);// set later date to current time plus 10 minutes 

Inspect the values, the dates match but the times differ

// write values to output window
Debug.Print(earlierDt.ToString());
Debug.Print(laterDt.ToString());

// giving us
08/08/2021 21:01:46
08/08/2021 21:11:46

Comparing these values will fail because the times are different. Use the Date property giving us just the date with zeroed time.

// write the Date property value 
Debug.Print(earlierDt.Date.ToString());
Debug.Print(laterDt.Date/ToString());

// giving us
08/08/2021 00:00:00
08/08/2021 00:00:00

Compare to see if the dates match.

if(earlierDt.Date == laterDt.Date)// compare Date property value
{// dates match
	
    // notify                            
    Debug.Print("Matched on date");
}

// giving us
Matched on date// success


#C#

Want to get started?

Contact James on 01244 722 302
Chester, Cheshire, U.K.

--