JRS: In article <11*********************@i40g2000cwc.googlegroups. com>,
dated Mon, 13 Mar 2006 02:56:31 remote, seen in
news:comp.lang.javascript, Tiya <Sw*********@gmail.com> posted :
I would like to know how to compare dates in javascript.
var sdate = new Date(theform.SubmissionDate.value);
var odate = new Date(theform.StartDate.value);
var todaysdate = new Date();
if(sdate < todaysdate)
{
alert("Submissionn Date should not be less than current date");
return false;
}
if(sdate < odate)
{
alert("Submissionn Date should not be less than opening date");
return false;
}
My above comparison does'nt work. can u suggest some way???
Slovenly ---^
The comparison code works correctly, and compares dates as desired.
Use, say,
alert(sdate + "\n" + odate + "\n" + todaysdate)
to see what your date strings have been interpreted as. Remember that
strings ##/##/## are liable to be taken as Merkin FFF, and perhaps in
the wrong centade.
Since real users may input incorrectly, put the dates in the alerts.
If sdate is a pure Date, and represents today, the message for the
comparison with todaysdate is questionable.
Read the newsgroup FAQ; see below.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.