I want to check that the expiration date is greater than another date.
[DisplayFormat(DataFormatString = "0:yyyy/MM/dd", ApplyFormatInEditMode = true)]
public DateTime? Date { get; set; }
[DisplayFormat(DataFormatString = "0:yyyy/MM/dd", ApplyFormatInEditMode = true)]
public DateTime? Expiration { get; set; }
How do I do this?
You need to create a custom validator to check your different dates using ValidationAttribute
.
Take a look of this link.
for example
DateTime date = DateTime.Now;
DateTime expiration = DateTime.Now.AddDays(3);
if (expiration > date)
you can compare dates like this
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.