Question

I'm trying to convert 6783 minutes to days, hours, and minutes but I can't get the hours correct. Now it's showing that 6783 is 5 days, 113 hours, and 3 minutes. As you can see the hours is completely wrong! Here's the code I'm currently using:

define('CONFIGURATION_HOURSPERDAY',     '24');
define('CONFIGURATION_HOURS',           intval((string)$stats->result->logonMinutes / 60));
define('ACTIVITY_DAYS',                 round(CONFIGURATION_HOURS / CONFIGURATION_HOURSPERDAY));
define('ACTIVITY_HOUR',                 intval((string)$stats->result->logonMinutes / 60));
define('ACTIVITY_MINUTES',              ((string)$stats->result->logonMinutes % 60));

if(ACTIVITY_DAYS > 0) {
    echo ACTIVITY_DAYS.' '.(ACTIVITY_DAYS == 1 ? 'day' : 'days');
}
echo ', '.ACTIVITY_HOUR.' '.(ACTIVITY_HOUR == 1 ? 'hour' : 'hours');
echo ', and '.ACTIVITY_MINUTES.' '.(ACTIVITY_MINUTES == 1 ? 'minute' : 'minutes');

$stats->result->logonMinutes contains the total minutes I have been online in EVE Online, which is 6783 minutes.

What should I do so it shows right amount of hours?

Thanks in advance.

Was it helpful?

Solution

You forgot to wrap hours as well as minutes.

define('ACTIVITY_HOUR', intval((string)$stats->result->logonMinutes / 60) % 24);

And... casting to string to divide something doesn't make much sense.

OTHER TIPS

$start = 6783;
$days = $start / 1440;
$start = $start % 1440;
$hours = $start / 60;
$start = $start % 60;
$minutes = $start;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top