compare two datetime values from SQL Server with c#

后端 未结 9 2247
终归单人心
终归单人心 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条回答
  •  时光取名叫无心
    2021-01-05 21:35

    The standard comparison operators (e.g. equality, less than, greater than) are overloaded for the DateTime type. So you can simply perform tests such as the following:

    var foo = DateTime.Parse("01/01/1900");
    var bar = DateTime.Now;
    
    var test1 = foo == bar; // false
    var test2 = foo != bar; // true
    var test3 = foo < bar; // true
    var test4 = foo > bar; // false
    

提交回复
热议问题