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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Date Compare

Status
Not open for further replies.

newbie14

Technical User
Feb 14, 2009
81
MY
Dear All,
I have 2 date object. I try to compare them but I dont get any results there. How can I do that ? My snippet of code is as below

var dateFrom=document.getElementById("myCalendar1").value;
dateFromArray=dateFrom.split("/");

var myDateFrom=new Date(dateFromArray[2],dateFromArray[1],dateFromArray[0]);

var dateTo=document.getElementById("myCalendar2").value;
dateToArray=dateTo.split("/");

var myDateTo=new Date(dateToArray[2],dateToArray[1],dateToArray[0]);


if(myDateFrom>myDateTo)
{
alert("Date To Must Be Less Than Date From"+myDateFrom);
}
 
Hi

Interesting, that code works for me in FireFox. Alternatively you could try like this :
Code:
if (myDateFrom[red].getTime()[/red]>myDateTo[red].getTime()[/red]) {
  alert("Date To Must Be Less Than Date From"+myDateFrom);
}
But I am quite sure the issue is elsewhere.

Feherke.
 
Hi Feherke,
Yes now it works is quite funny why when I put the extra code of getTime() it works. Thank you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top