Get passed time between 2 dates in yyyy-mm-dd format

Hello,
At the moment I’m working on a leaderboard that shows how long it took to claim a specific player badge after claiming another badge. For example a player claimed 2 badges. The first one for joining the game and the second one for defeating a boss. I want the time (in days) that took the player from joining the game to defeating the boss.

To get the claim dates of the badges im using the Badges Api v1 and for example it returns:

2021-01-02T15:57:42.624672Z

I only want days, months and years so i split it where the T is.

After that i split the date to get the day, month and year seperated.

Math is the issue I guess. I tried to get the difference by doing:

local ydiff = tonumber(year1) - tonumber(year)
local mdiff = tonumber(month1) - tonumber(month)
local ddiff = tonumber(day1) - tonumber(day)

And it works but i dont know what to do with the difference or if i even need it.

I dont know how to continue now and i hope someone can help me.

Thank You

Use DateTime.fromIsoDate(isoDate: string), pass the full string you get (do not split at T, pass the WHOLE thing).

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.