1

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");
Kritner
  • 13,557
  • 10
  • 46
  • 72

2 Answers2

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

According to the code above, MinimumValue is 3 days ago, MaximumValue is today.

EDIT: Out of curiosity between the actual difference between mine and Kritner's answer (.Now vs .Today) I came across this: https://stackoverflow.com/a/16268210/1017882 which seems well worth a read.

Community
  • 1
  • 1
  • 1
    Additionally "Now" is the current date and time, "Today" is just today's date (though you're dropping the time due to the ToString either way) – Kritner Oct 29 '14 at 14:48
2

You could do:

rvTxtTransactionDateFrom.MinimumValue = DateTime.Today.AddDays(-3).ToString("MM/dd/yy");
rvTxtTransactionDateFrom.MaximumValue = DateTime.Today.ToString("MM/dd/yy");
Kritner
  • 13,557
  • 10
  • 46
  • 72