View Full Version : due date script
oztinks
10-05-2002, 04:07 AM
Hi does anyone have a script that would return a due date (in my case 342 days) from an imput date, without reloading the page
I want to use it on my horse site so people can calculate the date of birth of their foals
x_goose_x
10-05-2002, 04:35 AM
maybe this'll help you get a start. If you need more help, just ask.
http://developer.irt.org/script/2.htm
oztinks
10-05-2002, 04:46 AM
Thanks goose
I am a cut and paste scripter (totally ingnorant)
I can see that this will return the number of days between two dates but how do I change it to return
input date + 342 days
someones at the door got to go
x_goose_x
10-05-2002, 02:40 PM
Try this:
<SCRIPT LANGUAGE="JavaScript"><!--
days = 342
function week_before(s) {
// parse s for month, day, year
var dateArray = s.split('/');
sdate = new Date(dateArray[2],dateArray[0]-1,dateArray[1]);
// figure out day, month, year 7 days ago
var odate = new Date(sdate.getTime() + (days * 86400000));
// return value
return (odate.getMonth()+1) + '/' + odate.getDate() + '/' + odate.getYear();
}
//--></SCRIPT>
<form>
<input type="text" name="thedate">
<input type="text" name="finaldate">
<input type="button" value="calculate" onclick="this.form.finaldate.value=week_before(this.form.thedate.value);">
</form>
I'm bad with dates, so this is jsut a variation of http://developer.irt.org/script/268.htm
This should do you
<HTML><HEAD><TITLE>Predate / Postdate</TITLE>
<SCRIPT language=JavaScript>
<!-- Predate / Postdate Script
// www.huntingground.freeserve.co.uk
timer=""
function calc(){
clearTimeout(timer)
days=document.f1.t1.value
if(isNaN(days)){ // check for number
show.innerText="Please Enter A Valid Number"
show2.innerHTML=" "
return}
txt="In "+days+" days time it will be:" // postdate display
if(document.f1.pre.checked==true){ // predate display
temp=days
days= -days
if(temp==1){
txt=temp+" day ago it was "}
else{
txt=temp+" days ago it was "
}
}
var now = new Date();
now.setTime(now.getTime() + days * 24 * 60 * 60 * 1000); // formula for calculation
show.innerText=now
if(document.f1.time[0].checked==false){ // display date
show2.innerText=txt
show.innerText=show.innerText.substring(0,10)+show.innerText.substring(show.innerText.length,show.in nerText.length-5)
}
else{ // display date and time, single days date figure
if(show.innerText.charAt(16)!=" "){
show.innerText=show.innerText.substring(0,10)+show.innerText.substring(show.innerText.length,show.in nerText.length-5)+" "+show.innerText.substring(10,19)
show2.innerText=txt
}
else{ // display date and time, double days date figure
show.innerText=show.innerText.substring(0,10)+show.innerText.substring(show.innerText.length,show.in nerText.length-5)+show.innerText.substring(10,19)
}
}
//timer=setTimeout("calc()",1000) // use for continuous update
}
// -->
</SCRIPT>
</HEAD><BODY><h1>Predate / Postdate</h1>
Use the following table to calculate the date of any number of days from now, forwards or backwards.
<center>
<P>
<form name=f1>
<table border="1" width="250">
<tr><td colspan="2" align="center"><span id='show2' style='visibility:visible'> </span></td></tr>
<tr><td colspan="2" align="center"><span id='show' style='visibility:visible'> </span></td></tr>
<tr><td align="center">Number of days <input type="text" name="t1" value="0" size="3" onclick="this.select()"></td><td> <input type="checkbox" name="pre" value="no" onclick="this.blur()"> PreDate<BR><input type="radio" name="time" value="yes" onclick="this.blur()">Time<BR><input type="radio" name="time" value="no" checked onclick="this.blur()"> No Time</td></tr>
<tr><td colspan="2" align="center"><input type="button" name="b1" value="Calculate" onclick="calc()" onclick="this.blur()"></td></tr>
</table>
</form>
</center>
</BODY>
</HTML>
oztinks
10-06-2002, 02:35 AM
Thanks goose
This is perfect. I had a look at the "irt" site, no way could I have altered the script to suit, think I will have to do some JS tutorials, hope I get as bad with dates as you soon.
Mr J thanks for the script too
Just a note:
Most of the general public will not be aware that the inputted date will have to be in the format of
Month, Date, Year
and may put
Date, Month, Year
This would affect the output of the script
I have modified the script so that the date can be entered as I think the general public would enter it
IE:
06/10/2002 (Date/Month/Year)
<SCRIPT LANGUAGE="JavaScript"><!--
days = 342
function week_before(s) {
// parse s for month, day, year
var dateArray = s.split('/');
sdate = new Date(dateArray[2],dateArray[1]-1,dateArray[0]);
// figure out day, month, year 7 days ago
var odate = new Date(sdate.getTime() + (days * 86400000));
// return value
return odate.getDate() + '/' + (odate.getMonth()+1) + '/' + odate.getYear();
}
//--></SCRIPT>
<form>
<input type="text" name="thedate">
<input type="text" name="finaldate">
<input type="button" value="calculate" onclick="this.form.finaldate.value=week_before(this.form.thedate.value);">
</form>
oztinks
10-07-2002, 12:43 AM
Thanks for that Mr J
I that will improve my form heaps, I was worried most people wouldn't understand MM/DD/YYYY without to many instructions.
Must make sure that they input the year as a 4 digit number though
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.