SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Count Up Script

  1. #1
    SitePoint Member
    Join Date
    Jul 2004
    Location
    philadelphia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Count Up Script

    I have the following code and it works fine for displaying the total amount of days + hours + minutes and seconds from a past date but I'm looking to extend the script to display the number of years, months (in 1 to 11 format), days (in less then year format). I need a code that can keep in that months have different number of days and also consider leap years. Can anyone help me?

    <script language="JavaScript1.2">

    function setcountup(theyear,themonth,theday){
    yr=theyear;mo=themonth;da=theday
    }

    setcountup(1997,1,31)

    var displaymessage="have passed since the debut of our site!"

    var countupwidth='95%'
    var countupheight='20px' //applicable only in NS4
    var countupbgcolor='lightyellow'
    var opentags='<font face="Verdana"><small>'
    var closetags='</small></font>'

    var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec")
    var crosscount=''

    function start_countup(){
    if (document.layers)
    document.countupnsmain.visibility="show"
    else if (document.all||document.getElementById)
    crosscount=document.getElementById&&!document.all?document.getElementById("countupie") : countupie
    countup()
    }

    if (document.all||document.getElementById)
    document.write('<span id="countupie" style="width:'+countupwidth+'; background-color:'+countupbgcolor+'"></span>')

    window.onload=start_countup


    function countup(){
    var today=new Date()
    var todayy=today.getYear()
    if (todayy < 1000)
    todayy+=1900
    var todaym=today.getMonth()
    var todayd=today.getDate()
    var todayh=today.getHours()
    var todaymin=today.getMinutes()
    var todaysec=today.getSeconds()
    var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec
    paststring=montharray[mo-1]+" "+da+", "+yr
    dd=Date.parse(todaystring)-Date.parse(paststring)
    dday=Math.floor(dd/(60*60*1000*24)*1)
    dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1)
    dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1)
    dsec=Math. floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*100
    0))/1000*1)

    if (document.layers){
    document.countupnsmain.document.countupnssub.document.write(opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags)
    document.countupnsmain.document.countupnssub.document.close()
    }
    else if (document.all||document.getElementById)
    crosscount.innerHTML=opentags+dday+ " days, "+dhour+" hours, "+dmin+" minutes, and "+dsec+" seconds "+displaymessage+closetags

    setTimeout("countup()",1000)
    }
    </script>

    To be more exact, I'm looking to count up from the date of January 31st, 1997. I need the format to show something similar to this:

    "7 years, 5 months, 29 days, 1 hours, 19 minutes, and 13 seconds have passed since the debut of our site!"

  2. #2
    SitePoint Member
    Join Date
    Jul 2004
    Location
    philadelphia
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    anyone?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2004
    Location
    newyork
    Posts
    30
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well if you want to display it in this format:

    "7 years, 5 months, 29 days, 1 hours, 19 minutes, and 13 seconds have passed since the debut of our site!"
    then you dont need to worry about leap year. that solves one of your problems


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •