I want to create a certain function that would activate on a certain MM/DD/YY. How could I do this? I'm not being super specific, but It's kinda tough to explain.
You can use os.date()
for this. os.date()
takes two variables, what time zone and what time (os.time()
).
For time zone you should pretty much always use "!(asterisk)t" which means UTC time, which is the standard, but if you want local timezone, use "(asterisk)t" instead. For time you should just leave it blank, because it takes os.time() automatically, unless you need to figure out what the date would be of a certain time.
Once you put it into a variable, it has the year, month, day, hour, minute, second, and several other things that might sometimes be useful. You can use this to compile any time into a date. An example would be using it to create the date of the time when the script was run.
time = os.date("!*t") print(time.month.."/"..time.day.."/"..time.year) -- mm/dd/yyyy
If you were to run the script right now, the script would print "11/10/2019"
into the output. If you were to run it sometime after, it would print the date of the day it was run.
For the question, you could make it so it detects what day it is, and if it is the day that function is supposed to run, it will call the function.