Os.time() calculation help

Basically, I’m making a temporary ban system and I want to calculate the number of hours and days until a ban is lifted and I am unsure how to do it.

Currently, to see if a person is banned, the server does the following calculation:

if tonumber(tab[i].BanStart) - os.time() > tonumber(tab[i].BanTime) then

Please note: BanStart is the os.time() of the server when the player was banned, and BanTime is the number of seconds they were banned for, in days or hours.

If the value is less than, it will ban them. I just want to display how many hours and minutes it will be until they are unbanned. I have the following function to convert it into hours and minutes.

local function toHMS(s)
	return ("%02i hours and %02i minutes"):format(s/60^2, s/60%60)

I’m pretty sure it’s something easy. Maths is not a subject I’m good at :joy::joy:

Many thanks in advance!


Flip these backwards(swap them). os.time() always rolls forward while BanStart is assumingly static.

1 Like

@Music_Jaxx os.time() returns seconds

you can use to see the month day hour minute

1 Like

That’s not correct. As the numbers go negative, it will never surpass BanTime. BanStart must be the logged time of first os.time() before ban.

For calculation of remaining time. tonumber(tab[i].BanTime) - (os.time() - tonumber(tab[i].BanStart)).


Thank you I edited the post

that’s it

1 Like

That works, thank you so much!