# Countdown Timer

## Recommended Posts

Here is my countdown timer that will also count up after it reaches zero. Was wondering how to do autoit math with remainders and non base 10 numbers. This was my test project just to see if it could be done.

```#include <Date.au3>

\$u=0; loop until
\$time = InputBox("Target Date", "Default 10 Days 15 Seconds" & @CRLF & "YYYY/MM/DD HH:MM:SS", \$date)

Do
Sleep(1000)

\$td = _DateDiff('s', _NowCalc(), \$time)

\$late = ""; dummy neg no
If \$td < 0 Then \$late = "-"; dummy neg yes
If \$td < 0 Then \$td = -\$td; convert neg \$td to pos for math

\$d = 0; Days with remainder math
If \$td > 86400 Then
\$dm = \$td
Do
\$dm = \$dm - 86400
\$d = \$d + 1
Until \$dm < 86400
EndIf

\$h = 0; Hours with remainder math
If \$td - (\$d * 86400) > 3600 Then
\$hm = \$td - (\$d * 86400)
Do
\$hm = \$hm - 3600
\$h = \$h + 1
Until \$hm < 3600
EndIf

\$m = 0; Miutes with remainder math
If \$td - (\$d * 86400) - (\$h * 3600) > 60 Then
\$mm = \$td - (\$d * 86400) - (\$h * 3600)
Do
\$mm = \$mm - 60
\$m = \$m + 1
Until \$mm < 60
EndIf

\$s = \$td - (\$d * 86400) - (\$h * 3600) - (\$m * 60); Seconds

\$db = ""; non zero for 2 digit numbers
\$hb = ""
\$mb = ""
\$sb = ""

If \$d < 10 Then \$db = 0; zero for 1 digit number
If \$h < 10 Then \$hb = 0
If \$m < 10 Then \$mb = 0
If \$s < 10 Then \$sb = 0

ToolTip("Target Date  " & \$time & @CRLF & "Time Left     " & \$late & \$db & \$d & ":" & \$hb & \$h & ":"  & \$mb & \$m & ":" & \$sb & \$s, 10, 10)

Until \$u = 1```

##### Share on other sites

\$time = InputBox("Target Date", "Default 10 Days 15 Seconds" & @CRLF & "YYYY/MM/DD HH:MM:SS", \$date)

What kind of accuracy!

## Create an account

Register a new account