Account join year fix

hey i am trying to do simple code that will show in the leaderboard join year of the player, i got stuck with it

game.Players.PlayerAdded:Connect(function(player)
        local joinYear = os.date("%Y", player.AccountAge)
	print(player.Name .. " joined in " .. joinYear)
end)
	

for some reason i get “joined in 1970”

Try printing just player.AccountAge

its not printing the year, its printing for example:

i joined 2016 and what i got is: “2649” i want to get the “2016”

Its printing the account age, not the date of join. That number is how days that user has been on the platform. So getting the current day - AccountAge, which give you the day they joined. So try using some math to figure out what year it is.

1 Like

yes thats what i am asking for help, i tried all i know

2649 is the days, first you need to divide it by 365, which in return will be 7.25…, then use math.round and then you subtract the current year with the number (7 in this case). And the number you get, in this example, 2023 - 7 is 2016.

And if you want a script, something like this:

game.Players.PlayerAdded:Connect(function(player)
	local date = os.date("*t")
	print(date) -- prints the table, you can check what things you can get
	local year = date["year"] -- the year
	print(year)
	local playerDays = player.AccountAge
	local subtractNumber = playerDays / 365
	local roundSubtractNumber = math.round(subtractNumber)
	local playerAge = year - roundSubtractNumber
	print(player.Name .. " joined in ".. playerAge)
end)
1 Like

you should probably familiarise yourself with how timestamps work
if you want 100% accuracy then you should use the apis and not divide the account age by 365 because that could have false flags if a leap year is involved (now that i think about it, it’s very unlikely to cause an issue but it’s still a probability and i prefer accuracy :rage:)

but since roblox is TOO PARANOID and doesn’t let you use their apis in-game (although they should just use unauthenticated requests but whatever), you’d have to use a proxy such as https://users.roproxy.com/v1/users/55495469 and extract the ‘created’ field

"created":"2014-02-03T19:16:57.357Z"

you can simply accomplish this by doing this

local HttpService = game:GetService("HttpService")

game.Players.PlayerAdded:Connect(function(player)
	local success, response = pcall(function()
		return HttpService:JSONDecode(HttpService:GetAsync("https://users.roproxy.com/v1/users/" .. player.UserId))
	end)
	if success and response ~= nil then
		local joinYear = string.split(response.created, "-")[1]
		print(player.Name .. " joined in " .. joinYear)
	else
		print("something went wrong. try enabling HTTP requests")
	end
end)

omg it’s functional!!
image

local currDay = math.floor(tick() / 86400) -- 60 * 60 * 24
local joinDate = currDay - player.AccountAge

joinDate will be the amount of days after January 1st, 1970

https://create.roblox.com/docs/reference/engine/globals/RobloxGlobals#tick