How to compare just the date part and not the time of two Dates?

后端 未结 6 1610
南旧
南旧 2020-12-29 21:30

I want to compare just the date part (and Not the time) of two VB.NET Date objects. Is there a way to do that?

6条回答
  •  半阙折子戏
    2020-12-29 21:49

    Change the txt1 date to format dd/mm/yyyy using myDateTime.ToShortDateString() so that both the dates will be in same format. then :

    if (DateTime.Compare(date1, date2) > 0) 
    // which means ("date1 > date2")
    if (DateTime.Compare(date1, date2) == 0) 
    //which means ("date1 == date2");
    if (DateTime.Compare(date1, date2) < 0) 
    //which means ("date1 < date2");
    

提交回复
热议问题