C# attribute to check whether one date is earlier than the other

前端 未结 6 1699
孤独总比滥情好
孤独总比滥情好 2021-02-07 15:05

I have a ViewModel for my MVC4 Prject containing two DateTime properties:

[Required]
[DataType(DataType.Date)]
public DateTime RentDate { get; set; }

[Required]         


        
6条回答
  •  眼角桃花
    2021-02-07 15:35

    Not sure of it's use in MVC/Razor, but..

    You can use DateTime.Compare(t1, t2) - t1 and t2 being the times you want to compare. It will return either -1, 0 or 1 depending on what the results are.

    Read more here: http://msdn.microsoft.com/en-us/library/system.datetime.compare.aspx

提交回复
热议问题