I need to compare two datetime variable only for some cri开发者_如何学运维teria : Day of the month and time .
If the day of the month and the time is equal to another datetime then the expression return true, the comparison must not keep in mind of the month and the year of the two Datetime .
What's the best way to do this comparison ?
Thanks.
Compare the Day and the TimeOfDay properties of the two DateTime values:
bool areEqual = (d1.Day == d2.Day)
&& (Math.Abs((d1.TimeOfDay - d2.TimeOfDay).TotalSeconds) < 1.0);
Adjust for different time zones before comparing if necessary.
精彩评论