Posted By

nebojsac on 06/13/11


Tagged

php minutes seconds


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

tux-world


Convert Seconds to Minutes PHP


 / Published in: PHP
 

URL: tricksbycinger.blogspot.com

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

  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";

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: ankit8 on April 2, 2013

hello...i am using one countdown timer in my online quiz....when user starts quiz i have to take to take tatabseime difference between start time and end time and that time difference i have to stored in minute and second format(i.e 1.30) in database.... problem is that i am not able to convert in that format...i am capturing time in seconds...help me

sending my code--

var mins var secs;

function cd() { mins = 1 * m("15"); // change minutes here secs = 0 + s(":01"); // change seconds here (always add an additional second to your total) redo(); }

function m(obj) { for(var i = 0; i < obj.length; i++) { if(obj.substring(i, i + 1) == ":") break; } return(obj.substring(0, i)); }

function s(obj) { for(var i = 0; i < obj.length; i++) { if(obj.substring(i, i + 1) == ":") break; } return(obj.substring(i + 1, obj.length)); }

function dis(mins,secs) { var disp; if(mins

You need to login to post a comment.