Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

date validation with no luck

Status
Not open for further replies.

tedi1

Technical User
Aug 25, 2002
87
IL
Hi,

I really don't know JavaScript but I have something to do with JavaScript.

I need to compare to dates that comes form form. I'll try to explain what I trying to do. They’re to Text boxes that hold the date in the form in the format of DD/MM/YYYY. I know that using the date() object requires to enter the date in (MM,DD,YYYY) format, so I splited the date on "/" and entered the date in the right order.
The problem is that I simply doesn't work
Why???
This is the code:
var fromdate = form2.date1.value
var todate = form2.date2.value
splitfromdate = fromdate.split("/");
splittodate = fromdate.split("/");
confromdate = new Date(splitfromdate[2].substr(2,2) , splitfromdate[1] , splitfromdate[0])
contodate = new Date(splittodate[2].substr(2,2) + "," + splittodate[1] + "," + splittodate[0])

if (confromdate >= contodate) {
alert ("'To' Date must be grater then 'From' Date");
return false;
}
 
See whether this helps
/*
* Function to compare two dates
*/
function compareDates(strFieldMinVal, strFieldMaxVal)
{
var arrData = new Array(3);
var intDay = 0;
var intMonth = 0;
var intYear = 0;
arrData = strFieldMinVal.split('/');
intMonth = parseInt(arrData[0], 10);
intDay = parseInt(arrData[1], 10);
intYear = parseInt(arrData[2], 10);
var dtStartDate = new Date(intYear, intMonth, intDay);
arrData = strFieldMaxVal.split('/');
intMonth = parseInt(arrData[0], 10);
intDay = parseInt(arrData[1], 10);
intYear = parseInt(arrData[2], 10);
var dtEndDate = new Date(intYear, intMonth, intDay);
if(dtEndDate.getTime() < dtStartDate.getTime())
{
return false;
}
return true;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top