Scripting math help

Hello, so I wrote this code below, I am trying to take in a seconds value and format it into a time format, I want to show how many days, minutes, seconds a player has been playing!

Currently, I have only been able to show exactly how many of either of these (days, hours, mins, ect…) by simple division, but I would like instead of just showing:

Output: "3d"

Show instead:

Output: "3d 12h 35m"

but my issue is the math, I am not the best with complex math, and I cant figure out how to do this, thank you for your help!

My code:

-- Rounds given time input
local function RoundTime(Time)

	return math.floor(Time); -- return math.floor(Time + 0.5);

end;

-- Format time for text
function Format_Module.FormatTime(Time)

	local Time_Formatted

	local Seconds = Time;

	local Minutes = RoundTime(Time / 60);

	local Hours = RoundTime(Minutes / 60);

	local Days = RoundTime(Hours / 24);

	local Years = RoundTime(Days / 365);
	
	print(Minutes, Hours, Days, Years)

	if Seconds < 60 then

		Time_Formatted = (Seconds.."s"); -- just seconds

	elseif Seconds > 60 and Minutes < 60 then

		if Minutes <= 1 then
			Time_Formatted = (Minutes.."m"); -- just minutes
		else
			Time_Formatted = (Minutes.."m"); -- just minutes
		end;

	elseif Minutes > 60 and Hours < 24 then

		if Hours <= 1 then
			Time_Formatted = (Hours.."h"); -- just hours
		else
			Time_Formatted = (Hours.."h"); -- just hours
		end;

	elseif Hours > 24 and Days < 365 then

		if Days <= 1 then
			Time_Formatted = (Days.."d"); -- just days
		else
			Time_Formatted = (Days.."d"); -- just days
		end;

	elseif Days > 365 then

		if Years <= 1 then
			Time_Formatted = (Years.."y"); -- Just years...
		else
			Time_Formatted = (Years.."y"); -- Just years...
		end;

	end;

	return Time_Formatted;

end;

ignore my code syntax, LUA is not my first language haha.

I think after more thought I have figured a method out.

local Seconds = 185

local Minutes = 185 / 60 -- (Output: 3)

local SecondsRemaining = Seconds - (60 * Minutes) -- (Output: 5)

If you have a better method please let me know!