mike1313 Posted March 29, 2007 Share Posted March 29, 2007 Ok I want a percent returned. I have a script that executes at roughly 6 am. How can I find out based on the current time how much of a percent it is until 6 am. As it gets closer to 6 am the % gets higher. Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 bump Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted March 29, 2007 Share Posted March 29, 2007 Percent of what? of the day? percent of time left since the last 6 am? Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 Percentage based on the time now until 6 am with the % getting higher as it gets closer to 6 am once at 6 am its 100% once it hits 6:01 am it starts over again at 0% Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 that or how can I find 6 am server time - current time and turn that into mins? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 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. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 something like: <?php $current_time = time() / 60; $total_time = 1440; $time_left = number_format((($total_time / $current_time) / 100), 2); ?> Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 that just returns 0.00. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 <?php $current_time = time() / 60; $total_time = 1440; $time_left = number_format((($total_time - $current_time) / 100), 2); ?> Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 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"; ?> Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 and did that work??? also, why are you dividing by 100 and then multiplying by 100? Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 well it was returning just aplain ole 44 Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 is there a way to divide the time stamp for 6 am? that way I could take the current timestamp - 6amstamp and turn it into a %? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 what do you mean divide the timestamp for 6am? Quote Link to comment Share on other sites More sharing options...
mike1313 Posted March 29, 2007 Author Share Posted March 29, 2007 I mean is there a way to find out what a certain part of the timestamp will be for 6 am, then find the current hour subtract the 2 and make it into a % that way? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 29, 2007 Share Posted March 29, 2007 time() returns the total amount of minutes from 12am. so, if it's 1am, time() will return 60. does that make sense? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 29, 2007 Share Posted March 29, 2007 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) . "%"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.