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

前端 未结 10 634
遇见更好的自我
遇见更好的自我 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:02

    if (StartDate < EndDate)
       // code
    

    if you just want the dates, and not the time

    if (StartDate.Date < EndDate.Date)
        // code
    

提交回复
热议问题