...

View Full Version : Countdown



Shaz
07-03-2003, 08:39 AM
Hi, has anybody seen/got some coding that will do this:

I have a field called Start Date. date/time only field.
Another field called Term (mths). integer only field
And another field called End Date. date/time only field.

I need to determine what the End Date will be based on the Start Date and Term.

ie:
Start Date = 1/7/2003
Term (mths) = 24
End Date will be 1/7/2005

Thanks in advance

Mr J
07-03-2003, 04:36 PM
I have this one but you have to enter days and not months,

Any good to you?





<SCRIPT LANGUAGE="JavaScript">
<!--
function calc_date(s) {
days=(document.f2.daynums.value*1)//-1
var dateArray = s.split('/');
sdate = new Date(dateArray[2],dateArray[1]-1,dateArray[0]);
if(dateArray[2].length<4){
alert("Please Enter The Year As A Four Digit Number\n\nExample:- 2002\n\nThank You")
return document.f2.date_to.value=""
}
else{
var odate = new Date(sdate.getTime() + (days * 86400000));
return odate.getDate() + '/' + (odate.getMonth()+1) + '/' + odate.getYear();
}
}
//-->
</SCRIPT>


<center>
<form name="f2">
<P><table border=1>
<tr><td>Start Date</td><td>Number of days</td><td>End Date</td></tr>

<tr><td><input type="text" name="date_from" size="10" value="25/09/2002"></td><td align="center"><input type="text" name="daynums" size="4" maxlength="4" value="5"></td><td><input type="text" name="date_to" size="10"></td></tr>
<tr><td colspan=3 align=center>
<input type="button" value="calculate" onclick="this.form.date_to.value=calc_date(this.form.date_from.value);">
</td></tr></table>
</form>
</center>

beetle
07-03-2003, 04:52 PM
function getEndDate( f )
{
var sDate = new Date( f.elements['Start_Date'].value );
sDate.setMonth( sDate.getMonth() + parseInt( f.elements['Term'].value, 10 ) );
f.elements['End_Date'].value = [sDate.getMonth()+1,sDate.getDate(),sDate.getFullYear()].join("/");
}Just pass a reference to the form into the function.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum