Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to convert minutes to days, hours and minutes?

Asked by 7 years ago
Edited 7 years ago

I've tried everything, but I can't make or find a formula that can do this. Basically you have an integer value that is minutes, and it gets converted to days, hours and minutes.

For example: 10 minutes > 0 days, 0 hours, 10 minutes | 86 minutes > 0 days, 1 hour, 26 minutes | 2000 minutes > 1 day, 9 hours, 20 minutes |

Is there any quick method to do this? Thanks for any answers.

0
I'm not sure this is what you want but... So the math is, from minutes to hours, you divide by 60, and for hours to days you divide by 24. Cyprus_Alexander 10 — 7y

3 answers

Log in to vote
2
Answered by 7 years ago

Hi!

Here is a pretty short method that converts minutes to days, hours, and minutes.

Let's start by setting the total minutes. Let's try 1526 minutes.

local timevalue = 1526

Firstly, we need to calculate the number of days in this time value. Since there are 1440 minutes in a day, we can divide the time value by that to get the days in decimals. However, we also need to floor it, which will return the rounded number down, so we can get a whole numbers of the days.

local days = math.floor(timevalue/1440) --1526/1440 rounded is 1 day!

Now, we must calculate the number of hours. Because there are 60 minutes in an hour, we divide the time value by that and round it down. However, we need to subtract it by the days as well. There are 24 hours in a day, so now we subtract the hours by the days*24. If there are 0 total days, it will not subtract it by anything.

local hours = math.floor(timevalue/60)-(days*24) --1526/60 rounded is 25 hours. Subtract the days*24 and we get 1 hour. That currently leaves us with 1 day and 1 hour.

Finally, it is time to calculate the remainder (the remaining minutes)! We can take the time value and subtract by the total minutes in the hours, and the total minutes in the days. Therefore, we can get our remaining minutes and complete the equation!

local minutes = timevalue-(hours*60)-(days*1440) --1526 subtracted by 1*60 subtracted by 1*1440 gives us 26 minutes!

Now, it's time to print our equation by days, hours and minutes.

print(days.." Days, "..hours.." Hours, "..minutes.." Minutes")

With this, 1526 will convert to: 1 Days, 1 Hours, 26 Minutes

And you're done! Here is the complete formula.

local timevalue = --Put minutes here
local days = math.floor(timevalue/1440)
local hours = math.floor(timevalue/60)-(days*24)
local minutes = timevalue-(hours*60)-(days*1440)
print(days.." Days, "..hours.." Hours, "..minutes.." Minutes")
0
Works like a charm, thank you! TheUnderNetwork 9 — 7y
Ad
Log in to vote
-1
Answered by 7 years ago
local minutes = 2000
local min = minutes%60
local hours = math.floor(minutes/60)%24
local days = math.floor(minutes/1440)
0
Explain yo code mann Goulstem 8144 — 7y
Log in to vote
-1
Answered by 7 years ago
function MinutesToDays(minutes)
    local min = tonumber(minutes)
    local days = math.floor(minutes / 1440)
    local hours = math.floor(min / 60) - (24 * days)
    local leftovers = (min % 60)
    print("Days: "..days..", Hours: "..hours..", Minutes: "..leftovers)
end

MinutesToDays(2000)
-- 1 day, 9 hrs, 20 minutes
0
Explain yo code mann Goulstem 8144 — 7y

Answer this question