Firstly you need to check the correct operator for equality. The expression
if (time1=time2)
will assign the value of time2 to time1. You need to use the correct operator:
if (time1 == time2)
Secondly, make use of the
DateTime Struct (System) | Microsoft Docs[
^] which contains methods, operators and properties to solve the majority of issues.