How do I check if a certain day has been passed?

So I’ve got a code system in which players can enter and receive prizes. However, it is a huge pain when I had to manually remove the code from the module script, the data is set up like this:
I would then do a simple if codeData[inputCode] then to then validate the code.

But is there a way to set up this data so that it checks if the additional data of [“Expires”] makes the code valid, and if it exceeds that date then it will not continue the rest of the code that awards the prize.


Hi there,

There is certainly a way to check the date using

I used this:

local date ="*t", os.time()) print(date.hour)

“*t” means local time for users. That depends on the time zone. “!*t” is UTC, or absolute time for the whole world. You can choose whichever one is more suitable for your case.

os.time() is the number of seconds from January 1, 1970 on 12:00 am. You input that as the second parameter. This then calculates what year, month, day, and etc. it is currently.

So the above currently returns:


13 is the hour of day (it is 1:00 pm for me, so it is correct!).
For the current situation, the code would be:

local code = {
	["Expire"] = {Year = 2019, Month = 12, Day = 23, Hour = 11, Minute = 0, Second = 0}

local date ="*t", os.time())
local expire = code.Expire

if date.year >= expire.Year and date.month >= expire.Month and >= expire.Day and date.hour >= expire.Hour and date.min >= expire.Minute and date.sec >= expire.Second then
	print("still got time!")

So, currently, this prints:

still got time!

because right now it is not December. You can use a system like this, replacing the print with your code, and your expiring system would work!

Hope that helps!


Using the == operator would mean that it’d have to directly be that, consider using the >= operator.
Also in, if a time is not given then it defaults it to os.time().


Thank you this is perfect! I will use this effectively

1 Like