0

Possible Duplicate:
How to add number of days to today’s date?

I would like to check how to add 3 days to date() so that the user cannot select any date within 3 days from today. Below is my code....

    function checkDate(sender, args) {
        if (sender._selectedDate < new Date()) {
            alert("You cannot select a day earlier than today!");
            sender._selectedDate = new Date();
            sender._textbox.set_Value(sender._selectedDate.format(sender._format))
        }
    }
Community
  • 1
  • 1

2 Answers2

0
var dateFromNow  = new Date();

dateFromNow = dateFromNow.setDate(dateFromNow.getDate()+3);

if(sender._selectedDate < dateFromNow){

//code
}
Riain McAtamney
  • 6,342
  • 17
  • 49
  • 62
0

Take a look at http://www.datejs.com/ (Its open source, contrary to the '.com').

You could then do:

if (sender._selectedData < Date.today().add(3).days()) { ... }

Also, according to How to add number of days to today's date?

var minDate = new Date();
minDate.setDate(minDate.getDate() + 3); 
if (sender._selectedData < minDate) { ... }
Community
  • 1
  • 1
Richard Schneider
  • 34,944
  • 9
  • 57
  • 73