Link to home
Start Free TrialLog in
Avatar of seopro
seopro

asked on

A very simple "customizable" countdown script

Hello,
I'm looking for a very simple customizable countdown script.
By "customizable", I mean that I need to define the start and the end dates.
For example:
Start date:26/05/08
End date:26/06/08
I'd appreciate all your help!
Thanks in advance!
ASKER CERTIFIED SOLUTION
Avatar of BrianGEFF719
BrianGEFF719
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobSampson
This one is VBScript in an HTA.  Save the code into Notepad with an HTA extension.

Regards,

Rob.
<head>
<title>Countdown</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Countdown"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>
<script language="VBScript">
' Declare global variable outside the Subs
Dim intSeconds, dteTo
 
Sub Window_onLoad
 intWidth = 640
 intHeight = 480
 Me.ResizeTo intWidth, intHeight
 Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
 
 dteTo = "25-Jul-2008 12:00:00 PM" 
 
 span_heading.innerHTML = "Countdown to " & dteTo
 intSecondsToDate = DateDiff("s", Now, CDate(dteTo))
 intDaysLeft = Int(intSecondsToDate \ 86400)
 intHoursLeft = Int((intSecondsToDate - (intDaysLeft * 86400)) \ 3600)
 intMinutesLeft = Int((intSecondsToDate - (intDaysLeft * 86400) - (intHoursLeft * 3600)) \ 60)
 intSecondsLeft = Int((intSecondsToDate - (intDaysLeft * 86400) - (intHoursLeft * 3600) - (intMinutesLeft * 60)))
 
 strHTML = intDaysLeft & " Days, " & intHoursLeft & " Hours, " & intMinutesLeft & " Minutes, " & intSecondsLeft & " Seconds"
 span_clock.innerHTML = strHTML
 
 iTimerID = window.setInterval("UpdateTimer", 1000)
End Sub
Sub UpdateTimer
 intSecondsToDate = DateDiff("s", Now, CDate(dteTo))
 intDaysLeft = Int(intSecondsToDate \ 86400)
 intHoursLeft = Int((intSecondsToDate - (intDaysLeft * 86400)) \ 3600)
 intMinutesLeft = Int((intSecondsToDate - (intDaysLeft * 86400) - (intHoursLeft * 3600)) \ 60)
 intSecondsLeft = Int((intSecondsToDate - (intDaysLeft * 86400) - (intHoursLeft * 3600) - (intMinutesLeft * 60)))
 
 strHTML = intDaysLeft & " Days, " & intHoursLeft & " Hours, " & intMinutesLeft & " Minutes, " & intSecondsLeft & " Seconds"
 span_clock.innerHTML = strHTML
End Sub
</script>
<body STYLE="font:14 pt arial; color:white;filter:progid:DXImageTransform.Microsoft.Gradient
(GradientType=1, StartColorStr='#000033', EndColorStr='#0000FF')">
      <table width='90%' height = '100%' align='center' border='0'>
            <tr>
                  <td align="center" colspan="2">
                        <h2><span id="span_heading">Countdown to 25-Jul-2008 12:00:00 PM</h2></span>
                  </td>
            </tr>
            <tr>
                  <td align="center">
                        <font size="4"><span id="span_clock">
                        </span></font>
                  </td>
            </tr>
            <tr>
                  <td align="center">
                        <br><input type='button' value='Close' name='btnClose' id='btnClose' onClick='vbs:window.close'>
                  </td>
            </tr>
      </table>
</body>

Open in new window

Avatar of seopro
seopro

ASKER

Hello,
Thanks for the useful link, BrianGEFF719!
RobSampson, Thanks for your code, But I was looking to put it on my website online, Not an HTA application.
But thanks anyway for all your help!
No problem.  If your web page supports VBScript, you can use the same code within it.  Otherwise, you could translate my code to Java and get it working....

Regards,

Rob.