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. Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/ 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? Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143337 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 Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143340 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."); } Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143350 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. Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143356 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"; ?> Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143358 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. Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143363 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 Link to comment https://forums.phpfreaks.com/topic/220753-time-formatting/#findComment-1143364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.