1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

(ttt) Date Countdown Script

Discussion in 'All Other Software' started by sparky222, May 6, 2004.

Thread Status:
Not open for further replies.
Advertisement
  1. sparky222

    sparky222 Thread Starter

    Joined:
    Jan 18, 2004
    Messages:
    129
    Does anyone know of a script that counts down days until a special even that can be used on a web page so that the number of days to a certain date is automatically updated? This is the kind of thing that was used when counting down to the Y2K.

    Thanks,

    counting
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
  3. sparky222

    sparky222 Thread Starter

    Joined:
    Jan 18, 2004
    Messages:
    129
    THANKS - but I don't quite have it yet. So far I have found a javascript to display and calculate the difference between two dates and I can default the date that I want to 2005-07-05 (July 5, 2004), but I don't know how to create a variable and input the current date in javascript into the form value. If I did that then the function would automatically calculate the number of days between TODAY and 2005-07-05. This is what I want to display on my web page.

    Here is the code I have so far:

    <script type="text/javascript">
    // ISO 8601 Gregorian Days Difference Demo

    function DaysDiff(D1, D2) { // Date Objects, with similar times
    return Math.round((D1-D2)/864e5) }

    function DiffDays(S1, S2) { // ISO date strings
    var X = ReadISO8601date(S1) ; if (X<0) return 'Date 1 bad'
    var Y = ReadISO8601date(S2) ; if (Y<0) return 'Date 2 bad'
    var Dx = Date.UTC(X[0], X[1]-1, X[2])
    var Dy = Date.UTC(Y[0], Y[1]-1, Y[2])
    return (Dx-Dy)/864e5 }

    function TryFrm1() { with (document.forms['Frm1']) {
    Diff1.value = DaysDiff(
    new Date(Date1.value.replace(/-/g, '/')),
    new Date(Date2.value.replace(/-/g, '/')) )
    Diff2.value = DiffDays(Date1.value.trim(), Date2.value.trim())
    Date1.focus() } }

    ShowFF(DaysDiff, DiffDays, TryFrm1, 9)

    var newDate="2004-05-07"

    </script>
    <form name=Frm1 action="#">
    <table align=center cellpadding=9 bgcolor=white summary="Days Difference">
    <tr><th>
    Find the number of days to July 5, 2005</th></tr>
    <tr><td>
    <!-- Input : ISO 8601 dates; 100-01-01 to 275760-09-13; in two ways :--><br>
    <input type=text name=Date1 value="2005-07-05" size=13 alt=" Date 1 "> -
    <input type=text name=Date2 value=+newDate+ size=13 alt=" Date 2 " >
    &#160;
    <input type=button name=BDiff value="Calculate" onClick="TryFrm1()">
    &#160;
    <input type=text name=Diff1 value="" size=9 readonly alt=" Result 1 ">
    &#160;
    <!-- <input type=text name=Diff2 value="" size=9 readonly alt=" Result 2 "> -->
    Results : Error Message or difference in Days.
    <br></td></tr></table>
    </form><br>


    Thanks for any help you can provide.
     
  4. sparky222

    sparky222 Thread Starter

    Joined:
    Jan 18, 2004
    Messages:
    129
    :) :) :) (y) LWDSquashman - Thanks - From the javascripts page you listed above I was able to find the exact scripts I was looking for. It gave me a script generator where I just entered the countdown date and it generated the javascript for me. FANTASTIC - Thanks again!
     
  5. sparky222

    sparky222 Thread Starter

    Joined:
    Jan 18, 2004
    Messages:
    129
  6. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/227036

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice