Jridi Naceur
Jridi Naceur

Reputation: 9

How do I compare between two input dates?

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?

Upvotes: 0

Views: 121

Answers (2)

Redwerk
Redwerk

Reputation: 56

for example

DateTime date = DateTime.Now;
DateTime expiration = DateTime.Now.AddDays(3);
if (expiration > date) 

you can compare dates like this

Upvotes: 1

Guillaume
Guillaume

Reputation: 844

You need to create a custom validator to check your different dates using ValidationAttribute.

Take a look of this link.

Upvotes: 1

Related Questions