What is the best way to compare the time of 2 DateTime objects?
For example
I just need to compare the time NOT the date.
Thanks
if (DateTime1.TimeOfDay > DateTime2.TimeOfDay)
{
MessageBox.Show("DateTime1 is later");
}
You can use DateTime.TimeOfDay to get just the time part to compare. This is essentially the same as if you did d - d.Date.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With