Jump to content

Recommended Posts

function seconds($int) {

if($int < 3600) {

$minutes = $int / 60;

$seconds = $int % 60;

 

$minutes = (int)$minutes;

$seconds = (int)$seconds;

 

if($minutes < 10) { $minutes = "0$minutes"; }

if($seconds < 10) { $seconds = "0$seconds"; }

 

$string = $minutes . "mins " . $seconds . "secs";

} else {

$hours = $int / 3600;

$minutes = $int % 3600 / 60;

$seconds = $int % 3600 % 60;

 

$hours = (int)$hours;

$minutes = (int)$minutes;

$seconds = (int)$seconds;

 

// if($hours < 10) { $hours = "0" . $hours . ""; }

// if($minutes < 10) { $minutes = "0" . $minutes . ""; }

if($seconds < 10) { $seconds = "0" . $seconds . ""; }

 

$string = $hours . "hrs " . $minutes . "mins " . $seconds . "secs";

}

 

return $string;

}

 

 

I need to add days to the time above, should be easy if you know what you are doing :) Thanks

Link to comment
https://forums.phpfreaks.com/topic/206402-add-days-to-time/
Share on other sites

Its ok, i figured it out, for anyone else who is interested in how i did it its like this

 

function seconds($int) {

if($int < 3600) {

$minutes = $int / 60;

$seconds = $int % 60;

 

$minutes = (int)$minutes;

$seconds = (int)$seconds;

 

if($minutes < 10) { $minutes = "0$minutes"; }

if($seconds < 10) { $seconds = "0$seconds"; }

 

$string = $minutes . "mins " . $seconds . "secs";

} elseif($int > 86400) {

$days = $int / 86400 % 7;

      $hours = $int / 3600 % 24;

$minutes = $int % 3600 / 60;

$seconds = $int % 3600 % 60;

 

$days = (int)$days;

$hours = (int)$hours;

$minutes = (int)$minutes;

$seconds = (int)$seconds;

 

// if($hours < 10) { $hours = "0" . $hours . ""; }

// if($minutes < 10) { $minutes = "0" . $minutes . ""; }

if($seconds < 10) { $seconds = "0" . $seconds . ""; }

 

$string = $days . "days " . $hours . "hrs " . $minutes . "mins " . $seconds . "secs";   

  } else {

$hours = $int / 3600;

$minutes = $int % 3600 / 60;

$seconds = $int % 3600 % 60;

 

$hours = (int)$hours;

$minutes = (int)$minutes;

$seconds = (int)$seconds;

 

// if($hours < 10) { $hours = "0" . $hours . ""; }

// if($minutes < 10) { $minutes = "0" . $minutes . ""; }

if($seconds < 10) { $seconds = "0" . $seconds . ""; }

 

$string = $hours . "hrs " . $minutes . "mins " . $seconds . "secs";

}

 

return $string;

}

Link to comment
https://forums.phpfreaks.com/topic/206402-add-days-to-time/#findComment-1079743
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.