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.
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.
1 | local days = math.floor(timevalue/ 1440 ) |
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.
1 | local hours = math.floor(timevalue/ 60 )-(days* 24 ) |
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!
1 | local minutes = timevalue-(hours* 60 )-(days* 1440 ) |
Now, it's time to print our equation by days, hours and minutes.
1 | 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.
2 | local days = math.floor(timevalue/ 1440 ) |
3 | local hours = math.floor(timevalue/ 60 )-(days* 24 ) |
4 | local minutes = timevalue-(hours* 60 )-(days* 1440 ) |
5 | print (days.. " Days, " ..hours.. " Hours, " ..minutes.. " Minutes" ) |