Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Countup

Status
Not open for further replies.

JonathanMayhew

IS-IT--Management
Jan 17, 2003
23
GB
Does anyone have a free script that counts up to a certain date. It must include years months and days (minutes and seconds are optional).

Thanks :)
 
is this what your looking for?


function DiffDate(dFrom, dTo){

var df=new Date(dFrom.getFullYear(),dFrom.getMonth(),
dFrom.getDate(), 0);
var dt=new Date(dTo.getFullYear(),dTo.getMonth(),
dTo.getDate(), 12);

return Math.floor( dt.valueOf()/(24*60*60*1000) -
df.valueOf()/(24*60*60*1000) );
}
 
Ermmm am a bit of a Javascript novice. It needs to go on a webpage. What part do I put in the <script> tag and what part do I put in the <body>.
 

the function goes in the script tag

<script type=&quot;text/javascript&quot;>

function DiffDate(dFrom, dTo){
var df=new Date(dFrom.getFullYear(),dFrom.getMonth(),
dFrom.getDate(), 0);
var dt=new Date(dTo.getFullYear(),dTo.getMonth(),
dTo.getDate(), 12);

return Math.floor( dt.valueOf()/(24*60*60*1000) -
df.valueOf()/(24*60*60*1000) );
}

</script>


the function will take 2 parameters
dFrom - the date you want to start counting
dTo - the date you want to finish


in the page you could write it like this

<body>
<script type=&quot;text/javascript&quot;>
// use 'mm/dd/yyyy' format
var dFrom = '12/31/2003';
var dTo = '01/12/2004'

document.write DiffDate(dFrom, dTo)
</script>
</body>


Not very functional as you can see - what is it you want to do with it ?


 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top