If so what is that command, because my app functions by day and is different daily. Please Help.
function setup()
d=os.date("*t")
for a,b in pairs(d) do
print(a,b)
end
end
function setup()
d=os.date("*t")
-- show all table entries for date
for a,b in pairs(d) do
print(a,b)
end
-- print some individual entries for date
print()
print("year ",d.year)
print("month ",d.month)
print("day ",d.day)
print("hour ",d.hour)
print("min ",d.min)
print("sec ",d.sec)
end
There’s a function for it on the Lua wiki:
-- returns the day of week integer and the name of the week
-- Compatible with Lua 5.0 and 5.1.
-- from sam_lie
function get_day_of_week(dd, mm, yy)
local days = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }
local mmx = mm
if (mm == 1) then mmx = 13; yy = yy-1 end
if (mm == 2) then mmx = 14; yy = yy-1 end
local val8 = dd + (mmx*2) + math.floor(((mmx+1)*3)/5) + yy + math.floor(yy/4) - math.floor(yy/100) + math.floor(yy/400) + 2
local val9 = math.floor(val8/7)
local dw = val8-(val9*7)
if (dw == 0) then
dw = 7
end
return dw, days[dw]
end
It appears that it returns two values, the first being the number of the days into the week (1-7), and the second being the name (such as “Mon” for Monday)
If you don’t know how to receive multiple values from a function, it works like this:
foo, bar = example() -- if "example" returned two values, the first would be stored in "foo" and the second in "bar"
(taken from here)
Edit: dave’s answer seems a bit simpler
wday gives you the day of the week. Sunday is wday 1. So wday 2 would be Monday.
@dave1707 @SkytheCoder thanks for the info. My code doesn’t recognize the wday variable
edit:i figured it out
function setup()
d=os.date(“*t”)
-- show all table entries for date
for a,b in pairs(d) do
print(a,b)
end
-- print some individual entries for date
print()
print("year ",d.year)
print("month ",d.month)
print("day ",d.day)
print("hour ",d.hour)
print("min ",d.min)
print("sec ",d.sec)
print("wday",d.wday)
wday=d.wday
print(wday)
end
function draw()
if wday==2 or wday==7 then
–do this
end
end
this is the code I am using to detect what day it is
@AnotherBoringUser You can use this.
function setup()
d=os.date("*t")
if d.wday==2 then
print("It's Monday")
elseif d.wday==7 then
print("It's Saturday")
end
end
Or this.
function setup()
day={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
d=os.date("*t")
print("it's ",day[d.wday])
end
Can someone tell me why this is not working(I tried it by setting my date ahead)
function setup()
day={"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"}
d=os.date("*t")
print("it's",day[d.wday])
Today=day[d.wday]
print(Today)
end
function draw()
background(255)
if Today==Friday then
background(0)
end
end
You need “” around Friday.
if Today=="Friday" then
background(0)
end
The days of the week in the table day
are string values. When you compare string values, you need to put " " around the value.