
i have two rad datepicker control. i want to valiate that User-entered date range should not exceed 90 days from the startdate using javascript. any one help me.
thx
chandrasekarank
4 Answers, 1 is accepted

One suggestion is to set the MaxDate property of the second RadDatePicker according to the date selected using first RadDatePicker. Set the MaxDate 90 days ahead of the first RadDatePicker's selected date, so that the rest of the days will not be selectable. Try the following Javascript:
JavaScript:
<script type="text/javascript"> |
function validate() |
{ |
var datepicker1 = $find("<%= RadDatePicker1.ClientID %>"); |
var date= datepicker1.get_selectedDate(); // Get the selected date from first datepicker |
var datepicker2 = $find("<%= RadDatePicker2.ClientID %>"); |
datepicker2.set_minDate(date); // Sets the MisDate |
date.setDate(date.getDate() + 90); //Adds 90 days |
datepicker2.set_maxDate(date); // Sets the MaxDate |
} |
</script> |
Thanks,
Princy.

Thank u for ur idea..based on that i have fullfilled my requrirement and i have added the coding also..
thx,
chandrasekaranK
function Validate90Days1()
{
var txtFromDate = document.getElementById('<%=txtFromDate.ClientID %>');
var txtToDate = document.getElementById('<%=txtToDate.ClientID %>');
var getyy = txtFromDate.value.substring(0, 4);
var getmm = txtFromDate.value.substring(5, 7);
var getdd = txtFromDate.value.substring(8, 10);
var mydate = getmm + "/" + getdd + "/" + getyy;
var x = new Date(mydate);
var y= x.getFullYear();
var m= x.getMonth()+1; // added +1 because javascript counts month from 0
var d= x.getDate()+ 90;
mydate = m +
"/" + d + "/" + y;
var objdateFrom = new Date(mydate);
var getyyTO = txtToDate.value.substring(0, 4);
var getmmTO = txtToDate.value.substring(5, 7);
var getddTO = txtToDate.value.substring(8, 10);
var mydateTO = getmmTO + "/" + getddTO + "/" + getyyTO;
var objToDate = new Date(mydateTO);
if (objdateFrom < objToDate)
{
alert(
"Date range should not exceed 90 days");
return false;
}
}
function Validate90Days()
{
var fromdateControl = document.getElementById('<%=txtFromDate.ClientID %>');
var todateControl = document.getElementById('<%=txtToDate.ClientID %>');
var fromDateValue = fromdateControl.value;
var dayPartFromDate = parseInt(fromDateValue.substring(8, 10), 10);
var monPartFromDate = parseInt(fromDateValue.substring(5, 8), 10);
var yearPartFromDate = parseInt(fromDateValue.substring(0, 5), 10);
var dtFrom = new Date(yearPartFromDate, monPartFromDate - 1, dayPartFromDate);
var toDateValue = todateControl.value;
var dayPartToDate = parseInt(toDateValue.substring(8, 10), 10);
var monPartToDate = parseInt(toDateValue.substring(5, 8), 10);
var yearPartToDate = parseInt(toDateValue.substring(0, 5), 10);
var dtTo = new Date(yearPartToDate, monPartToDate - 1, dayPartToDate);
if (fromDateValue != "")
{
var one_day = 1000 * 60 * 60 * 24;
var days = (dtTo.getTime() - dtFrom.getTime()) / (one_day);
if (days > 90) {
alert(
'To Date should not be greater than 90 days from the From Date');
return false;
}
}
}


var today = new Date();
//alert(today);
var future_date = new Date('2012/01/26 13:03:35 GMT-0400');
//alert(future_date);
var difference = today.getTime() - future_date.getTime();
var thirty_days = 3600 * 24 * 90 * 1000;
//alert(difference);
if(difference > thirty_days)
{
alert(false);
}
else
{
alert(true);
}