karimali831 Posted October 20, 2010 Share Posted October 20, 2010 Hi! I have got a problem with this function: <?php function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0, "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if($time >= 31556926){ $value["years"] = floor($time/31556926); $time = ($time%31556926); } if($time >= 86400){ $value["days"] = floor($time/86400); $time = ($time%86400); } if($time >= 3600){ $value["hours"] = floor($time/3600); $time = ($time%3600); } if($time >= 60){ $value["minutes"] = floor($time/60); $time = ($time%60); } $value["seconds"] = floor($time); return (array) $value; }else{ return (bool) FALSE; } } ?> and my output for example: echo Sec2Time(604800); returns = "Array" ?? What I am wanting is to return a time from how many seconds. 604800 is 7 days so I want it to say 7 days. 2419200 is 1 month so I want it to say 1 month or 4 weeks. is (above) the right function for what I want ? thanks. Quote Link to comment Share on other sites More sharing options...
karimali831 Posted October 20, 2010 Author Share Posted October 20, 2010 I have changed it slightly which I hope it works, yes? function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0, "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if($time >= 31556926){ return $value["years"] = floor($time/31556926). " Years"; $time = ($time%31556926); } elseif($time >= 86400){ return $value["days"] = floor($time/86400). " Days"; $time = ($time%86400); } elseif($time >= 3600){ return $value["hours"] = floor($time/3600). " Hours"; $time = ($time%3600); } elseif($time >= 60){ return $value["minutes"] = floor($time/60). " Minutes"; $time = ($time%60); } else return $time ." Seconds"; }else{ return (bool) FALSE; } } Quote Link to comment Share on other sites More sharing options...
AbraCadaver Posted October 20, 2010 Share Posted October 20, 2010 Well, you don't have any logic in there for months or weeks, and I haven't checked the logic that is there, but given the current function you would do something like: $result = Sec2Time(604800); echo $result['Years'] . ' ' . $result['Days'] . ' ' . $result['Hours'] . ' ' . $result['Minutes'] . ' ' . $result['Seconds']; 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.