views:

687

answers:

4

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 be 75%.

Given the current time, how could you work out the amount of day that already passed?

+3  A: 

24hours are 100% so 24/currentTime = result 100 / result = % ;)

Sebastian Sedlak
A: 

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

Petoj
+7  A: 

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
sykora
Thanks, worked a treat :)
Tom
+2  A: 

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;
gkrogers