Convert Seconds to Minutes PHP


/ Published in: PHP
Save to your folder(s)

Takes the seconds, and returns minutes. Will wrap it in a function is anyone is interested. Example: 92s -> 1m 32s


Copy this code and paste it in your HTML
  1. $seconds = 60;
  2. echo "seconds = $seconds<br />";
  3. $start_seconds = round($seconds);
  4. if($start_seconds <60)
  5. {
  6. $minutes ="";
  7. $seconds = $start_seconds;
  8. }
  9. else
  10. {
  11.  
  12. $minutes = floor($start_seconds/60);
  13. $seconds = $start_seconds - $minutes*60;
  14.  
  15. $minutes = "$minutes"."m";
  16. $seconds = $seconds."s";
  17. }
  18. echo "$minutes $seconds";

URL: tricksbycinger.blogspot.com

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.