Search code examples
c#asp.netasp.net-validators

Range Validator validate that date selected was within the past 3 days


I have a range Validator i use with a jquery calendar select. I want to set the minimum value to be 3 days ago with the maximum value being today (for a valid range of 3 days ago to today). How can I accomplish this?

 rvTxtTransactionDateFrom.MinimumValue = // how to set to today - 3 days?
 rvTxtTransactionDateFrom.MaximumValue = DateTime.Today.ToString("MM/dd/yy");

Solution

  • You could do:

    rvTxtTransactionDateFrom.MinimumValue = DateTime.Today.AddDays(-3).ToString("MM/dd/yy");
    rvTxtTransactionDateFrom.MaximumValue = DateTime.Today.ToString("MM/dd/yy");