How to check if one DateTime is greater than the other in C#

前端 未结 10 627
遇见更好的自我
遇见更好的自我 2021-02-03 16:28

I have two DateTime objects: StartDate and EndDate. I want to make sure StartDate is before EndDate. How is this

10条回答
  •  攒了一身酷
    2021-02-03 17:12

    You can use the overloaded < or > operators.

    For example:

    DateTime d1 = new DateTime(2008, 1, 1);
    DateTime d2 = new DateTime(2008, 1, 2);
    if (d1 < d2) { ...
    

提交回复
热议问题