Date/Time Format Strings Help

Hello i need help to make “account age” with “.”

for example:
image
as you can see 5.30 Years

in my script its only showing without the “.”
for example for me its:

5 years

i read Date/Time Format Strings and still can’t undarstand.

here is my code:


local dateTime = DateTime.fromUnixTimestamp(86400 * accAge)

local yearsOfAge = tonumber(dateTime:FormatUniversalTime('YYYY'+ 'M', 'en-us')) - 1970

i appreciate a lot.

2 Likes

it’s very easy to get the month/day/year from unix timestamp

but how can i get in my output for example “5.3” years and not “5”??

can you please show me i am trying do that about a hour please
???

Simple format.

This should work.


game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "Leaderstats"
	local AgeValue = Instance.new("IntValue",leaderstats)
	AgeValue.Name = "Age"
	
	local dateTime = DateTime.fromUnixTimestamp(86400 * plr.AccountAge)

	local yearsOfAge = tonumber(dateTime:FormatUniversalTime('YYYY' .. 'M' .. 'en-us')) - 1970
	
	AgeValue.Value = yearsOfAge
end)

1 Like

missing argument #3 (string expected)

But tell us where. If you don’t tell us where the errors are we can’t help you

https://gyazo.com/c9cbefb0730d44f961eeb34ae5283b5b
line 16 “missing argument #3 (string expected)”

can you please help i don’t know how to fix that

I’m not sure what you want, but try this

local Player = game:GetService("Players").LocalPlayer
print(Player.AccountAge/365) -- in my case it is 5.008, I joined in 2016.

Well surely there is a much easier way to get what you want without all this dateTime stuff you can just do:

game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	local AgeValue = Instance.new("NumberValue",leaderstats)
	AgeValue.Name = "Age"
	
	local playerAge = plr.AccountAge
	playerAge /= 365 -- Format players account age to years
	
	AgeValue.Value = playerAge-playerAge % 0.1 -- Truncate number to 1 decimal place
end)

and how i can put in my output only 2 decimals?

for example my account age is: “5.0821917808219” and i want in my output be “5.08”

you could use math.floor

local Player = game:GetService("Players").LocalPlayer
local Years = math.floor(Player.AccountAge/365 * 100)/100
print(Years)

change 100 by the number of decimal places according to zeros

10 = one decimal
100 = two decimal places

and so with everything

1 Like

thanks a lot i appreciate a lot

1 Like