How do I make a countdown to Christmas?

How do I make a countdown to Christmas? I have looked at a handful of posts on countdowns, I’ve tried a few ways but it’s only be counting down seconds, this is the script i made based off what I found on the forums:

local epoch = 1608786000
local diff = epoch - os.time()
local count = os.date("!*t", diff)

local day = count.yday/86400
local hour = count.hour/60^2%24
local min = count.min/60%60
local sec = count.sec%60

print(string.format("%02i:%02i:%02i:%02i", day, hour, min, sec))
1 Like

I’m not sure what you did wrong to be exact but I managed to throw together a working countdown with what you had started:

while wait(1) do
    local epoch = 1608786000
    local diff = epoch - os.time()
    local count = os.date("*t", diff)
    print(string.format("%02i", count.day)..":"..string.format("%02i", count.hour)..":"..string.format("%02i", count.min)..":"..string.format("%02i", count.sec))
end

Really no math is required on the variables in the count table because they’re already calculated for you, and rather than trying to format the whole thing at once I formatted each element individually to have a width of 2.

Hope this helps!

1 Like