...

View Full Version : Help on date comparisons



trsands
02-03-2004, 06:24 PM
Can someone tell me why this always produces an output
"After today" indicating that the date is after today no matter what start date I enter (including today)

function dated(){


var dstart = document.forms.tstest.stdate;
var dend = document.forms.tstest.endate;
var dtest = document.forms.tstest.testfield;

var startstr = dstart.value; // mm/dd/yyyy
var endstr = dend.value;

var xdtoday = new Date();

var syear = parseInt(startstr.substring(6,10));
var smonth = parseInt(startstr.substring(0,2));
var sday = parseInt(startstr.substring(3,5));

var eyear = parseInt(endstr.substring(6,10));
var emonth = parseInt(endstr.substring(0,2));
var eday = parseInt(endstr.substring(3,5));

var xstart = new Date(syear,smonth,sday);
var xend = new Date(eyear,emonth,eday);


if (xdtoday > xstart )
dtest.value = "Before today";

if (xdtoday == xstart )
dtest.value = "Equal today";

if (xdtoday < xstart )
dtest.value = "After today";

}
//

trsands
02-03-2004, 07:00 PM
NEVER MIND!! Sorry folks

There was a bug in the date input subroutine (forgot to subtract 1 from month)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum