Jump to content

php time help again


mike1313

Recommended Posts

Percent of what? of the day? percent of time left since the last 6 am?

 

i'm pretty sure that's what he's looking for. this is more of a math question than a PHP question. i'd start with the number of minutes in a day: 1440. then i'd get the current time using time() and convert it into minutes. then, subractthe current time from 1440, and convert it into percent. boom. you're done.

Link to comment
Share on other sites

no thats returned negative. I had this....

 

<? 
$sixamtime = ((((time() / 60) / 24) / 3600) / 7);
$six = 60 * 6;
        $total_time = 1440;

        $percentage = round((($total_time / $sixamtime) / 100) * 100);

echo "$percentage";
?>

Link to comment
Share on other sites

I think this may be what you are looking for.  Except if it's 0600 it will display 0%.  It will also probably display 100% prematurely because of the rounding.  Just force it to round down using the floor function, then it won't display 100% from 0545 until 0559, but will display 99% instead.

 

//hour: int from 0 - 23
$control_hour = 6;

//minute: int from 0 - 59
$control_minute = 0;

$current_hour = date("G");
$current_minute = date("i");

$minutes_in_day = 24 * 60;

$expired = (($current_hour * 60) + $current_minute) - (($control_hour * 60) + $control_minute);
$expired = ($expired < 0) ? $expired + $minutes_in_day : $expired;

echo round(($expired / $minutes_in_day) * 100) . "%";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.