Date Calculation

L

Laura Hast

I need to insert a javascript date calculation on a webpage. I need to calc
today's date minus a start_date to give me a count of the days

example

today - start_date = count_days

I don't know how to trigger the java_script to call this function.

Can anyone help me with this code. It's for a class and I'm designing a
website that was due last weekend.

Thanks!
 
P

P@tty Ayers

Laura Hast said:
I need to insert a javascript date calculation on a webpage. I need to
calc today's date minus a start_date to give me a count of the days

example

today - start_date = count_days

This script works for me, if it's what you need. Obviously you need to
change the "March 17, 2004" and the "St. Patrick's day" to whatever you want
it to be.

---------------------------------------------------

Put in body of page where statement needs to go.

<script language="JavaScript">
<!--
var now= new Date();
var stpats = new Date("March 17, 2004" );
var how_long= stpats.getTime() - now.getTime();
var days = Math.ceil(how_long/ (60*60*1000*24));
var from= (how_long<0)? "since":"until"
document.write("There are "+days+" days "+from+" St. Patrick's day.")
//-->
</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top