Player account creation date detection

What I want to do is detect which year a Roblox account was created using the https service. Originally, I thought I could just use accountage and substract the current year from that but I realized that once new year happens then it will auto set the Roblox account creation date in game to +1 even though it should wait till the actual day for ex may or April when ever it was created.

3 Likes

tried using player.AccountAge?
it gives you account age in days (as far as i know) but if you divide it buy 365 it abd round it it should give you the age.

1 Like

The thing is the game gives out titles titles based on the join date for ex 2013,2016,2020 etc

1 Like

Let’s say a player joined April 5th 2020 and they log on on in January of 2024 then I think it would switch to 4 years instead of waiting until April 5

1 Like

oh i get it but dont know how to archive it srry.
maybe this can help idk https://devforum.roblox.com/t/how-to-make-a-real-time-account-creation-tracker/1914121

Can I use the Roblox api instead?

i guess so… i dont really understand how this script works

Yes.
You can use https://users.roblox.com/v1/users/{id}
However, roblox servers do not allow you to access the roblox api directly, so you have to change the url to https://users.roproxy.com/v1/users/{id}

local http = game:GetService("HttpService")
local id = 1
local res = http:GetAsync("https://users.roproxy.com/v1/users/"..id)
local data = http:JSONDecode(res)
local joinDate = data.created

The documentation for this API is under Swagger UI.

You don’t even need HttpsService for this use case. Here’s a more practical way of utilizing Player.AccountAge:

  • Using the account age (the amount of days since the account was created), multiply it by 86400 to get the amount of seconds
  • Subtract the current time from the calculated account age in seconds, this will give you the timestamp of when the account was created.
  • Lastly, get the year of the timestamp of when the account was created.
function getCreationYear(plr: Player)
	local seconds_since_creation = (plr.AccountAge * 86400) -- Amount of seconds since the account was created
	local account_created_seconds = os.time() - seconds_since_creation -- The exact time the account was created
	local date = os.date("%Y", account_created_seconds) -- Get the year of when the account was created
	return tonumber(date)
end
1 Like

But how about leap days how could I align teh code for that

os.date() already accounts for leap days.

1 Like

Pretty much what I want to do is give a player the veteran tag if they created their account in 2006-2008 or classic in 2009-2012 etc

Sorry to be nitpicky - but isn’t it 86,400 seconds in a day - not 84,600?

1 Like

Just noticed that! Thanks, I fixed it.

In that case, use if and else conditions to check if a user goes into a specific group. Here’s a small sample of the full code:

local players = game:GetService("Players")

function getCreationYear(plr: Player)
	local seconds_since_creation = (plr.AccountAge * 86400) -- Amount of seconds since the account was created
	local account_created_seconds = os.time() - seconds_since_creation -- The exact time the account was created
	local date = os.date("%Y", account_created_seconds) -- Get the year of when the account was created
	return tonumber(date)
end

players.PlayerAdded:Connect(function(plr)
	age = getCreationYear(plr)
	if age <= 2012 then
		if age >= 2006 and age <= 2008 then
			print("Veteran")
		else
			print("Classic")
		end
	else
		print("Not Veteran or Classic")
	end
end)

If you need more then 2 tags, then it would be better to use tables/dictionaries instead (see post below).

1 Like
function YearCreated(P:Player)
	local SecondsOld = P.AccountAge * 86400
	local TimeStamp = os.time() - SecondsOld
	local Year = tonumber(os.date("%Y", TimeStamp))
	return Year
end

local Tags = {
	{Date = 2006,Tag="Veteran"},
	{Date = 2010,Tag="Classic"},
	{Date = 2015,Tag="Seasoned"},
	{Date = 2020,Tag="COVID"},
	{Date = 2024,Tag="Noob"},
}
function GetTag(Player:Player)
	local PlayerAge = YearCreated(Player)
	for _,Tags in ipairs(Tags) do
		if Tags.Date > PlayerAge then
			return Tags.Tag
		end
	end
	return nil
end

This should suit your purposes :slight_smile:

1 Like

Yeah I was thinking of using tables cuz ima use math.clamp for the year ranges for each tag

Also how would I detect a player anniversary? Would I need to make a separate variable for the creation date and access the month and day and do the same thing with the current day

You basically reuse the same exact getCreationYear() code. The only change is to use the parameter *t for os.date():

function getAnniversaryDate(plr: Player)
	local seconds_since_creation = plr.AccountAge * 86400 -- Amount of seconds since the account was created
	local account_created_seconds = os.time() - seconds_since_creation -- The exact time the account was created
	local date = os.date("*t", account_created_seconds) -- Returns a dictionary of values for the date
	return date
end

The variable date will give you a dictionary with all the dates you need (the day, month, year the account was created etc). Note that the values with in the dictionary return a number (e.g. month returns between 1 (January) and 12 (December)), so you’ll need to code accordingly.

An example of how you can use this function:

local players = game:GetService("Players")
local months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}

function getAnniversaryDate(plr: Player)
	local seconds_since_creation = (plr.AccountAge * 86400) -- Amount of seconds since the account was created
	local account_created_seconds = os.time() - seconds_since_creation -- The exact time the account was created
	return os.date("*t", account_created_seconds) -- Get the year of when the account was created
end

players.PlayerAdded:Connect(function(plr)
	local dict = getAnniversaryDate(plr)
	print(string.format("%s was created on: %s %s, %s", plr.Name, months[dict.month], dict.day, dict.year))
end)

Even better, you can also use the getAnniversaryDate() function to fetch the date of the year the account was created, by simply using dict.year. Like this:

players.PlayerAdded:Connect(function(plr)
	local dict = getAnniversaryDate(plr)
	print(string.format("%s was created on: %s %s, %s", plr.Name, months[dict.month], dict.day, dict.year))
	print(string.format("%s was created in the year %s", plr.Name, dict.year))
end)
1 Like