How to check what day it is

Hey everyone!

For Christmas this year, I’m making an advent calendar but I need to know what day it is so that specific day will open the daily door.

I’m not sure how to do this.

I’m guessing I would use os.time() or os.date() but I don’t know how to implement that into my game. Link

Thanks in advance!

first you can get the date you want it to end at,
subtract that from the current date.
And use os.difftime to get the difference.

Then chuck that into os.date("%j",timediffence) and you should have the amount of days until christmas from the Unix epoch.

2 Likes

You could do something like this:

local CurrentDate=os.date("!*t", os.time())
if CurrentDate.month==12 then -- Only Run code when month is december
	if CurrentDate.day==1 then -- Add Code For Day1 GiveAway
	elseif CurrentDate.day==2 then -- Add Code For Day2 GiveAway
	-- and so on.
	end
end

No the script you sent returns UTC time

local CurrentDate=os.date("!*t", os.time()) -- returns UTC time, lua table
local CurrentDate=os.date("*t", os.time()) -- returns player time, lua table
1 Like

You can do:

os.date("%a", os.time())
1 Like

Thank you so much and @Deadwoodx for helping me with that.

Although I’ve encounted another problem. Would you know how I would make it say the door was unavailable after the date?

Since there is 25 doors, writing something like this isn’t good scripting:

local Calendar = script.Parent
local Frame = Calendar.Parent

local CurrentDate=os.date("*t", os.time())
if CurrentDate.month == 12 then
	if CurrentDate.day == 1 then
		Calendar["1"].BackgroundColor3 = Color3.fromRGB(115,255,115)
		Calendar["1"].Button.Text = "CLAIM"
	elseif CurrentDate.day == 2 then
		Calendar["1"].BackgroundColor3 = Color3.fromRGB(150, 150, 150)
		Calendar["1"].Button.Text = "UNAVAILABLE"
		Calendar["2"].BackgroundColor3 = Color3.fromRGB(115,255,115)
		Calendar["2"].Button.Text = "CLAIM"
	elseif CurrentDate.day == 3 then
		Calendar["1"].BackgroundColor3 = Color3.fromRGB(150, 150, 150)
		Calendar["1"].Button.Text = "UNAVAILABLE"
		Calendar["2"].BackgroundColor3 = Color3.fromRGB(150, 150, 150)
		Calendar["2"].Button.Text = "UNAVAILABLE"
		Calendar["3"].BackgroundColor3 = Color3.fromRGB(115,255,115)
		Calendar["3"].Button.Text = "CLAIM"

--and carry on all the way to 25
	end
end

Is there any sort of way of how to know that if a day has passed, the previous doors become unavailable. Would you have to use arrays?

Thanks in advance!

1 Like

Try this:

local dateofplayer = os.date("*t") -- a lua table
local day = dateofplayer["day"]
local month = dateofplayer["month"]
local year = dateofplayer["year"]

Now using these variables make your door using if and elseif statements

Also if you type os.date("*t")

-- It returns
-- {
                    ["day"] = 21,
                    ["hour"] = 17,
                    ["isdst"] = false,
                    ["min"] = 56,
                    ["month"] = 11,
                    ["sec"] = 23,
                    ["wday"] = 1,
                    ["yday"] = 325,
                    ["year"] = 2021
}

You could just reset all the doors to unavailable at the beginning and then set the current days door to claim:

local Calendar = script.Parent
local Frame = Calendar.Parent

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

if CurrentDate.month == 12 then
	-- First Reset all doors to unavailable
	for _,day in ipairs(Calendar:GetChildren()) do
		day.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
		day.Button.Text = "UNAVAILABLE"
	end
	
	-- Set todays calander to claim
	local TodaysDoor=Calendar[tostring(CurrentDate.day)]
	TodaysDoor.BackgroundColor3 = Color3.fromRGB(115,255,115)
	TodaysDoor.Button.Text = "CLAIM"
end

Sorry for not posting any pictures.

Here is what I want it to look like.

eg) It is the 2nd of December today

So they will say coming soon but if the day is passed it is unavailable.

Thank you so much!

In that case you could do something like this:

local Calendar = script.Parent
local Frame = Calendar.Parent

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

if CurrentDate.month == 12 then
	for _,day in ipairs(Calendar:GetChildren()) do
		
        local dayNo=tonumber(day.Name)
		if dayNo<CurrentDate.day then -- dayNo is less than today so mark as unavailable 
			day.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
			day.Button.Text = "UNAVAILABLE"
		elseif dayNo==CurrentDate.day then -- dayNo is today
			day.BackgroundColor3 = Color3.fromRGB(115,255,115)
			day.Button.Text = "CLAIM"
		elseif dayNo>CurrentDate.day then -- dayNo is greater than today so set to coming soon
			day.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
			day.Button.Text = "COMING SOON"	
		end
	end

end

Thanks for replying, I imported it into my game but it doesn’t seem to work… To test it I set it to CurrentDate.month == 11 for November but all it does is making 18 unavailable.

I also need a way for the script not to pick up on Script and the UIGridLayout. I know this can be used by using Instance:IsA() but again, I’m too stupid to figure out how to do it.

image

Thanks!

Try this:

local Calendar = script.Parent
local Frame = Calendar.Parent

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

if CurrentDate.month == 12 then
	for _,day in ipairs(Calendar:GetChildren()) do
        if day:IsA("Frame") then
			local dayNo=tonumber(day.Name)
			if dayNo<CurrentDate.day then -- dayNo is less than today so mark as unavailable 
				day.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
				day.Button.Text = "UNAVAILABLE"
			elseif dayNo==CurrentDate.day then -- dayNo is today
				day.BackgroundColor3 = Color3.fromRGB(115,255,115)
				day.Button.Text = "CLAIM"
			elseif dayNo>CurrentDate.day then -- dayNo is greater than today so set to coming soon
				day.BackgroundColor3 = Color3.fromRGB(150, 150, 150)
				day.Button.Text = "COMING SOON"	
			end
		end
	end

end

It works! Thank you.

Is there datastores that once you’ve claimed your daily door, you can’t rejoin an claim it again?

Also, how to I make a counter that says how many ‘Christmas points’ you have, then when you reach 10 it gives you a badge. You earn 1 Christmas point for opening 1 door.

Yes, you will need to set up a datastore to keep track of players who have already claimed for that day, the datastore could also keep a record of how many ‘Christmas points’ the player has - but since this is now a question about DataStores/Badges you should really create a new post asking for help on these subjects and mark this post as Solved. It helps other users who are looking for answers to similar questions find the solutions they need too.