Link to home
Start Free TrialLog in
Avatar of trg_dk
trg_dkFlag for Denmark

asked on

Calculate date difference in YMD format "20081008"

On a submit page, I have 2 Select's - startdate, enddate.
Each holds a calculated value and allows the user to select a startdate and a enddate, submit the form and retrieve data.

Now I need to verify the form before submitting it, that startdate < enddate AND the difference between the dates are <= 4 weeks/31 days.

The function I've made so far is below - but I need osme help on how to verify the max. date difference.

Cheers,
Mark

function valiDates(){
		var maxtime = 60*60*24*31;
		var btn = document.getElementById("submit");
		var strSd = document.getElementById("startdate").value;
		var strEd = document.getElementById("enddate").value;
		var sd = new Date( strSd.substring(0,3) +"/"+ strSd.substring(4,5) +"/"+ strSd.substring(6,7) );
		var ed = new Date( strEd.substring(0,3) +"/"+ strEd.substring(4,5) +"/"+ strEd.substring(6,7) );
		if (sd > ed ){
			btn.disabled = true;
			btn.value = 'Slut dato skal være senere end start dato, max 4 uger statistik kan dannes !';
			document.getElementById("alert1").style.visibility = 'visible';
			} else {
			btn.disabled = false;
			btn.value = 'Hent data';
			document.getElementById("alert1").style.visibility = 'hidden';
			}			
	}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of 1eEurope
1eEurope
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of trg_dk

ASKER

YOU da' man :-)

Thanks for your quick solution - works perfectly !!!