Calculate duration between two dates

Hello! So, I wanted to make a script that calculates the duration between two dates. Meaning, if I provide a month, a day, and a year, and then the second month, day and year, it should calculate the time. I thought about using os.time to do it but is there any way to convert Epoch time to a readable date? Thanks!

Os.Difftime

Takes the input from the first date to the second date and gives you the difference.
(In seconds)

you can use the os.date and

Oh and you can convert the os.date to legible text using.
print(os.date(“*t”, 906000490))

Found a nice article if you need to do it manually: Programming in Lua : 22.1

1 Like

you can use math

local time1 = os.time()
local time2 = os.time() -- at a different time

local function round (num)
	return math.floor(num + 0.5)
end

local difference = time2 - time1

local seconds = difference

local days = round(difference / 86400)

local months = round(days / 12)

local years = round(days / 365)

print(seconds,days,months,years)
1 Like

Thank you! I really appreciate the help!

Thank you! I’ll keep this solution in mind as well!