Slightly strange question, but hopefully someone can help.
In essence, if the time was 12pm the the elapsed percentage would be 50%, 6am would be 25% and 16pm would
Assuming you can get the current time of day, it'd be pretty easy to calculate the percentage of the day elapsed.
percentage = (hours / 24 + minutes / (60 * 24)) * 100
The accepted answer bugs me for many reasons including the relationship to a real life calendar. Personally, I would probably do this:
<?php
$start = strtotime("today");
$end = strtotime("tomorrow");
$now = time();
$secondstoday = $end - $start;
$secondselapsed = $now - $start;
$percentage = ($secondselapsed / $secondstoday ) * 100;
printf('%.2f%% of the day has passed (%d out of %d seconds)', $percentage, $secondselapsed, $secondstoday);
result:
72.22% of the day has passed (62402 out of 86400 seconds)
You could then extend it even further by making a function and changing the range from "today"
and "tomorrow"
to something else.
gettimeofday(true) returns the number of seconds elapsed since midnight as a float (I think), so you want: gettimeofday(true)/(60*60*24)
. Multiply by 100 to get a percentage.
EDIT: Actually, gettimeofday returns the number of seconds elapsed since the start of the epoch, so you need to subtract midnight:
$midnight = strtotime('00:00');
$epochseconds = gettimeofday(true);
$timeofdayseconds = $epochseconds - $midnight;
$timepercent = $timeofdayseconds/(60*60*24)*100;
24hours are 100% so 24/currentTime = result 100 / result = % ;)
I dont know php but is there any way to get the current date witch i guess :P can you extract the hours out of this or minutes how exact do you want it to be?, Current hours/24 * 100 :P current minutes/1440 * 100