Forum Moderators: open
<script type="text/javascript">//Set the two dates
var startingdate=new Date(1997, 5, 11) //Month is 0-11 in JavaScript
var today=new Date()
//Get 1 day in milliseconds
var one_day=1000*60*60*24
//Calculate difference btw the two dates, and convert to days
document.write(Math.ceil((today.getTime()-startingdate.getTime())/(one_day))+
" days has gone by since widgets.com started!")
</script>
I have modified the script slightly.
Just hope that this is what you had invisaged ;)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>from today</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /><style type="text/css">
/*<![CDATA[*/
body {
background:#cccccc;
}
input {
width:40px;
margin:3px;
}
#sbmt,#rst {
width:62px;
}
div#cntnt {
position:absolute;
top:20%; /*adjust this to position - y*/
left:40%; /*adjust this to position - x*/
background:#ffffff;
padding:10px;
border:double 6px #000000;
width:160px;
font-family:arial;
font-size:14px;
}
/*//]]>*/
</style><script type="text/javascript">
//<![CDATA[
function daysTo(year,month,day){
//Check for numbers only
if(isNaN(document.forms[0][0].value) ¦¦ isNaN(document.forms[0][1].value) ¦¦ isNaN(document.forms[0][2].value)){
alert("numbers only thankyou!");return;
}
//Set the two dates
var startingdate=new Date(year,month-1,day); //Month is 0-11 in JavaScript
var today=new Date();//Get 1 day in milliseconds
var one_day=1000*60*60*24;//Calculate difference btw the two dates, and convert to days
document.forms[0][3].value=-Math.floor((today.getTime()-startingdate.getTime())/(one_day));}
//]]>
</script></head>
<body><div id="cntnt">From today's date
<form action=""><div>
<input type="text"/> : year <br />
<input type="text"/> : month <br />
<input type="text"/> : day <br />
<input type="text"/> : no. of days <br />
<input id="sbmt" type="submit" value="submit"
onclick="daysTo(document.forms[0][0].value,document.forms[0][1].value,document.forms[0][2].value);return false"/>
<input id="rst" type="reset"/>
</div></form>
</div></body>
</html>
Unfortunately this forum does not render code accurately.
When you C & P this code to test it you will have to amend this line...
if(isNaN(document.forms[0][0].value)¦¦isNaN(document.forms[0][1].value)¦¦isNaN(document.forms[0][2].value)){
birdbrain
No problem ;)
This will calculate the number of days between two dates.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>from today</title>
<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /><style type="text/css">
/*<![CDATA[*/
body {
background:#cccccc;
}
input {
width:60px;
margin:3px;
font-family:arial;
font-size:14px;
}
#sbmt,#rst {
width:62px;
}
div#cntnt {
position:absolute;
top:20%; /*adjust this to position - y*/
left:40%; /*adjust this to position - x*/
background:#ffffff;
padding:10px;
border:double 6px #000000;
width:240px;
font-family:arial;
font-size:14px;
}
/*//]]>*/
</style>
<script type="text/javascript">
//<![CDATA[
function daysTo(year,month,day,year1,month1,day1){
for(i=0;i<6;i++){
if(isNaN(document.forms[0][2+i].value)){
alert("numbers only thankyou!");
return;
}
}
var startingdate=new Date(year,month-1,day);
var finishingdate=new Date(year1,month1-1,day1);
var today=new Date();
var one_day=1000*60*60*24;document.forms[0][8].value=Math.floor((today.getTime()-startingdate.getTime()+(finishingdate.getTime()-today.getTime()))/(one_day));
}
//]]>
</script>
</head>
<body><div id="cntnt">
<form action="">
<table><tr>
<td><input type="text" readonly="readonly"value="1st date"/></td><td><input type="text" readonly="readonly"value="2nd date"/></td><td> </td></tr><tr>
<td><input type="text"/></td><td><input type="text"/></td><td> : year </td></tr><tr>
<td><input type="text"/></td><td><input type="text"/></td><td> : month </td></tr><tr>
<td><input type="text"/></td><td><input type="text"/> </td><td>: day </td></tr><tr>
<td> </td><td><input type="text"/></td><td>: no. of days </td></tr><tr>
<td><input id="sbmt" type="submit" value="submit"
onclick="daysTo(document.forms[0][2].value,document.forms[0][4].value,document.forms[0][6].value,
document.forms[0][3].value,document.forms[0][5].value,document.forms[0][7].value);return false"/>
</td><td><input id="rst" type="reset"/></td><td> </td>
</tr></table>
</form>
</div></body>
</html>
I hope that this helps ;)
birdbrain