dean7 Posted December 5, 2010 Share Posted December 5, 2010 Hi all, I have features on my website which require a time limit untill they can do the thing agian, but at the current mintue ive got the time in seconds. How can I make a function which will give the time in minutes instaid of seconds. Example: If it was a 2 mintue waiting time instaid of being 120 Seconds it will be 2min(s) 0sec(s). Example of my Current Code: $timewaiting = time() + 160; // Waiting time. (2min) if ($user->lasttime > time()){ $howlongleft = $user->lasttime - time(); echo ("You must wait $howlongleft"); Thanks for any help given. Quote Link to comment Share on other sites More sharing options...
requinix Posted December 5, 2010 Share Posted December 5, 2010 Do you not know how to convert a number of seconds into a number of minutes? Really? Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2010 Author Share Posted December 5, 2010 Do you not know how to convert a number of seconds into a number of minutes? Really? Well not really, thats why im asking? Im rather new to PHP :S Quote Link to comment Share on other sites More sharing options...
ikin Posted December 5, 2010 Share Posted December 5, 2010 $timewaiting = time() + 160; // Waiting time. (2min) if ((time()-$timewaiting) < time()){ $howlongleft = $timewaiting - time(); echo ("You must wait $howlongleft seconds."); } Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2010 Author Share Posted December 5, 2010 $timewaiting = time() + 160; // Waiting time. (2min) if ((time()-$timewaiting) < time()){ $howlongleft = $timewaiting - time(); echo ("You must wait $howlongleft seconds."); } That only seems to echo 160. Thanks for the reply though. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted December 5, 2010 Share Posted December 5, 2010 To format the result, which I believe was the original question: $minutes = floor($howlongleft / 60); // number of whole minutes left $secs = sprintf('%02d', $howlongleft % 60); // remainder of time left (in seconds) divided by 60. echo "$minutes:$secs"; ?> Quote Link to comment Share on other sites More sharing options...
ikin Posted December 5, 2010 Share Posted December 5, 2010 $timewaiting = time() + 160; // Waiting time. (2min) if ((time()-$timewaiting) < time()){ $howlongleft = $timewaiting - time(); echo ("You must wait $howlongleft seconds."); } That only seems to echo 160. Thanks for the reply though. Because you got to add the time to like a database, because there you only add the time then check = only gives the time you gave. Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2010 Author Share Posted December 5, 2010 To format the result, which I believe was the original question: $minutes = floor($howlongleft / 60); // number of whole minutes left $secs = sprintf('%02d', $howlongleft % 60); // remainder of time left (in seconds) divided by 60. echo "$minutes:$secs"; ?> Yeah thanks, worked just how I wanted it . Thanks 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.