function CheckDataValue(txtDateFromClientID, txtDateToClientID)
{
var txtDateFrom = document.getElementById(txtDateFromClientID);
var txtDateTo = document.getElementById(txtDateToClientID);
if (txtDateFrom.value.length == 0 || txtDateTo.value.length==0)
{
alert("Please select From date and To date ");
event.returnValue = false;
return false;
}
var DateFrom = txtDateFrom.value;
var DateTo = txtDateTo.value;
var FromMonth = DateFrom.substring(0,DateFrom.indexOf('/'));
var FromDay = DateFrom.substring(2, DateFrom.lastIndexOf('/'));
var FromYear = DateFrom.substring(DateFrom.lastIndexOf('/') + 1, DateFrom.length);
var ToMonth = DateTo.substring(0,DateTo.indexOf('/'));
var ToDay = DateTo.substring(2, DateTo.lastIndexOf('/'));
var ToYear = DateTo.substring(DateTo.lastIndexOf('/') + 1, DateTo.length);
if(!(isValidDate(FromDay,FromMonth,FromYear)) || !(isValidDate(ToDay,ToMonth,ToYear)))
{
alert("Please ensure that typed dates should be valid");
event.returnValue = false;
return false;
}
var dateDiff = daysBetween(txtDateTo.value, txtDateFrom.value);
if(dateDiff<0)
{
alert("Please ensure that To date should be larger than From date");
event.returnValue = false;
return false;
}
var newDateFrom = new Date(txtDateFrom.value);
var newDateTo = new Date(txtDateTo.value);
//alert(newDateFrom.getMonth()+1);
// alert(newDateTo.getFullYear());
//var newMonthFrom = newDateFrom.getMonth()+1;
//var newMonthTo = newDateTo.getMonth()+1;
var months = monthDiff(newDateFrom,newDateTo);
if(months>6)
{
alert("Please ensure that the difference should be less than 6 months");
event.returnValue = false;
return false;
}
}
function daysBetween(DateOne, DateTwo) {
var OneMonth = DateOne.substring(0, DateOne.indexOf('/'));
var OneDay = DateOne.substring(3, DateOne.lastIndexOf('/'));
var OneYear = DateOne.substring(DateOne.lastIndexOf('/') + 1, DateOne.length);
var TwoMonth = DateTwo.substring(0, DateTwo.indexOf('/'));
var TwoDay = DateTwo.substring(3, DateTwo.lastIndexOf('/'));
var TwoYear = DateTwo.substring(DateTwo.lastIndexOf('/') + 1, DateTwo.length);
var cha = ((Date.parse(OneMonth + '/' + OneDay + '/' + OneYear) - Date.parse(TwoMonth + '/' + TwoDay + '/' + TwoYear)) / 86400000);
return cha;
}
function monthDiff(d1, d2) {
var months;
months = (d2.getFullYear() - d1.getFullYear()) * 12;
months -= d1.getMonth() + 1;
months += d2.getMonth() +1;
//alert(months);
return months;
}
function isValidDate(day, month, year) {
if (month < 1 || month > 12) {
return false;
}
if (day < 1 || day > 31) {
return false;
}
if ((month == 4 || month == 6 || month == 9 || month == 11) && (day == 31))
{
return false;
}
if (month == 2) {
var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day == 29 && !leap)) {
return false;
}
}
return true;
}