How do i get the days since a place was created? I want the my game to display it’s age (in days) in a certain spot of the map, but i don’t know how to do so.
To get the days since a place was created, you’ll need to get the information from the place first using MarketplaceService:GetProductInfo()
.
local ms = game:GetService("MarketplaceService")
local id = 25415 -- change this to your liking
local information = ms:GetProductInfo(id)
From there, MarketplaceService:GetProductInfo()
returns a Created
property, which is when the place was created. Note that this property, returns an ISO date, for example:
print(information.Created) -- prints "2008-01-26T01:36:49.157Z" (for id 25415)
You can use the Created
property and convert it to a timestamp with DateTime.fromIsoDate()
, after which you can use the UnixTimestamp
property:
local timestamp = DateTime.fromIsoDate(information.Created).UnixTimestamp
print(timestamp) -- prints 1201311409 (for id 25415)
Now, you can compare the timestamp from there to now with os.difftime()
and os.time()
. You can also use math.floor
if the decimals aren’t necessary. Afterwards, you can get the amount of days since the place was created:
local difference = os.difftime(os.time(), timestamp)
local days = math.floor(difference / 86400)
print(days .. " days ago")
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.