I need to write a formatting function for the number of seconds a member has been on a site. the system already counts the seconds and handles sessions and everything. here is the code I have now.
function format_seconds($sc){$mn=0; $hr=0; $dy=0; $wk=0; $mo=0; $yr=0;
while($sc>=60){$mn++; $sc-=60;}
while($mn>=60){$hr++; $mn-=60;}
while($hr>=24){$dy++; $hr-=24;} while($dy>=7){$wk++; $day-=7;}
while($wk>=4){$mo++; $wk-=4;} while($mo>=12){$yr++; $mo-=12;}
return(array('sc'=>$sc,'mn'=>$mn,'hr'=>$hr,'dy'=>$dy,'wk'=>$wk,'mo'=>$mo,'yr'=>$yr));}
I need it to format the seconds like this:
0yr 0mn 0wk 0dy 0:0:0
my function works, but the problem is it's very inefficient when it comes to larger numbers. when it gets up to over a few years, php acts like it's locked up, trying to convert the seconds to minutes. the date function wont work because of all the other formatting things in it. leap years and daylight savings and all that. I need just a simple seconds to minutes hours weeks converter. anyone else know of a way?