compare two datetime values from SQL Server with c#

后端 未结 9 2260
终归单人心
终归单人心 2021-01-05 20:48

i want to know how compare two datetime values one who is retreived from sql database and the other is the current one with c#

9条回答
  •  梦毁少年i
    2021-01-05 21:35

    You can use the DateTime.CompareTo method.

    Usage is like this:

    firstDateTime.CompareTo(secondDatetime);
    

    and returns an int as a result which indicates

    Less than zero - This instance is earlier than value.

    Zero - This instance is the same as value.

    Greater than zero - This instance is later than value.

提交回复
热议问题