Countdown script not displaying correct time to 2021

I have a countdown script counting down to 2021 (my games release date) and it says 2021 is 29 days away.

My script:

local countdownText = script.Parent.LabelCountdown



local day = os.time({year = 2021, month = 1, day = 1, hour = 1, min = 1, sec = 1})

while wait() do

        local secondsBetween = os.difftime(day, os.time())

        local seconds = secondsBetween % 60
        local minutes = math.floor(secondsBetween % (60*60) / 60)
        local hours = math.floor(secondsBetween % (60*60*24) / (60*60))
        local days = math.floor(secondsBetween % (60*60*24*30) / (60*60*24))

        local textString = days .. "d:" .. hours .. "h:" .. minutes .. "m:" .. seconds .. "s"
        countdownText.Text = textString

        if secondsBetween <= 0 then break end
end

It displays the string (textString) to a textlabel in my gui. any help? thanks.
additionally ; I’d like help on my current code, due to me being in a bad state and exhausted. thanks

You can use a IntValue and use that IntValue to display the seconds of countdown.

Thanks for the reply. I’ll see if anyone can help with my current code, since I am extremely worn out I’ve been working all day. I’ll try your method out if no one else can help.

When dealing with real life time conversions you can use os.date() to simplify the process. But for the reasoning it was only showing up to 31 days is you were not doing anything to account for the months till the end of the year. Once you account for the months you should have an accurate time.


This was the edited script I came up with (I adapted it to use the os.date library for easier readability and you can read more about it here) the time is currently set to account for the player’s timezone except you can replace "*t" with "!*t" to display the time in UTC.

local countdownText = script.Parent.LabelCountdown

local day = os.time({year = 2021, month = 1, day = 1, hour = 1, min = 1, sec = 1})

while wait() do
	
	local secondsBetween = os.difftime(day, os.time())
	local dateTable = os.date("*t",secondsBetween)
		
	local textString = dateTable["month"].." Months,"..dateTable["day"].." Days,"..dateTable["hour"].." Hours,"..dateTable["min"].." Minutes,"..dateTable["sec"].." Seconds!"
	countdownText.Text = textString
	
	if secondsBetween <= 0 then break end
end