How can I get the Account Age of somebody not in-game?

Hello,
I was working on adding timed bans, when I ran into a wall. I cant exactly get the account age of somebody out of the game.

I went looking in the API and found the https://users.roblox.com/v1/users/* endpoint, but that returns a date, which doesn’t really help me.
"created": "2016-06-08T21:50:52.52Z",

I’m just looking for a simple number on how many days since their account creation. Thank you!

Someone already made a post like this:

local example = "2012-06-17T13:52:09.243Z"
local day, time = string.match(example, "(%d+%-%d+%-%d+)T(%d+:%d+:%d+%.%d+)Z")

Another post on github:

function parse_json_date(json_date)
    local pattern = "(%d+)%-(%d+)%-(%d+)%a(%d+)%:(%d+)%:([%d%.]+)([Z%+%-])(%d?%d?)%:?(%d?%d?)"
    local year, month, day, hour, minute, 
        seconds, offsetsign, offsethour, offsetmin = json_date:match(pattern)
    local timestamp = os.time{year = year, month = month, 
        day = day, hour = hour, min = minute, sec = seconds}
    local offset = 0
    if offsetsign ~= 'Z' then
      offset = tonumber(offsethour) * 60 + tonumber(offsetmin)
      if xoffset == "-" then offset = offset * -1 end
    end
    
    return timestamp + offset
end

print(string.format('%d', parse_json_date('2017-05-25T06:21:43Z')))
print(string.format('%d', parse_json_date('2017-05-25T06:21:43+0830')))
print(string.format('%d', parse_json_date('2017-05-25T06:21:43-0400')))
print(string.format('%d', parse_json_date('2017-05-25T06:21:43.213Z')))
1 Like

You could also just use the DateTime library. The method the OP would want is DateTime.fromIsoDate:

-- Example
local dateData = DateTime.fromIsoDate("2016-06-08T21:50:52.52Z"):ToLocalTime()
print(dateData.Year) -- Prints 2016

Hey, the code is returning a date string, when I was trying to make it a plain number (such as 123)
image