5

I do not know where to ask about this kinda stuff so I thought why not ask Stackoverflow?

I wonder if it's possible to get the current day somehow, with Lua?

Something about os.date() but I have no idea how to do it. Or maybe os.time() ?

like:

local day = os.time()somethingsomething

And then check

if (day == 'monday') then
print('It is monday')
elseif (day == 'tuesday') then
print('It is tuesday!')
end

2 Answers2

3

Why not to Google it? There is an excelent article here. See http://www.lua.org/pil/22.1.html

Try print(os.date("%A")) for getting day of week.

To check if it's monday now you can write any of those conditions.

if (os.date("%A") == "Monday") then
  print("It's Monday")
end
if (os.date("*t").wday == 1) then
  print("It's Monday")
end
Seagull
  • 13,484
  • 2
  • 33
  • 45
2

If you need the named days:

local daysoftheweek={"Sunday","Monday","Tuesday","Wednesday","Thrusday","Friday","Saturday"}
local day=daysoftheweek[os.date("*t").wday]
print(day)

Or you can just use os.date("*t").wday and it will return 1 for Sunday, 2 for Monday, etc.

gwell
  • 2,695
  • 20
  • 20