Comparing Two dates

Hiii …

I have two date fields in a web appl. and am using applet so

to select date.Now when i m comparing those date field value

in JSHEADER using javascript it is showing wrong results.For

e.g if Fromdate is greater than Todate then it should prompt

Fromdate cannot be greater than Todate…so i have written

Javascript like this…

if(document.forms[0].F_Date.value >= document.forms[0].T_Date.value)

{

        msg+="\r To Date should be Grater Than From Date";

        msgflag="true";

}

Above code not able to fulfill the purpose.Pls help f any body

know any other method.

Thanks

Saswat

Subject: RE: Comparing Two dates

Try the below code:

var form = document.forms[0];

Var Fromdate = new Date(form.F_Date.value);

var Todate = new Date(form.T_Date.value);

if (Fromdate.getTime() >= Todate.getTime()) {

msg += “\r To Date should be grater than From Date”;

msgflag = “true”

}

HTH

Adi

Subject: RE: Comparing Two dates

I googled and found following JavaScript that contains a function for comparing dates:http://www.mattkruse.com/javascript/date/source.html

hth

Subject: RE: Comparing Two dates

Here is the code … for Date you can use a simple text field , look at the code below its ´very simple and reusable …

karthik

FromDate = document.forms[0].ValidFromTx.value;

var FromDateDT= FromDate.split(“.”);

var FromDateDTresult = FromDateDT[1]+“/”+FromDateDT[2]+“/”+FromDateDT[0];

startdate = new Date(FromDateDTresult);

ToDate = document.forms[0].ValidToTx.value;

var ToDateDT= ToDate.split(“.”);;

var ToDateDTresult =ToDateDT[1]+“/”+ToDateDT[2]+“/”+ToDateDT[0];

enddate = new Date(ToDateDTresult);

if (Date.parse(startdate)>Date.parse(enddate))

{

 alert("From Date cannot be less than To Date . Please Verify  !!!");

 document.forms[0].ConditionValidFromTx.focus();

 return false ; 

}

else

{

alert (“Valid Date Information information saved …”);

}