Jump to content

[SOLVED] help with this please.


seany123

Recommended Posts

here is the code...

 

<?php
function timeSince($urtime)
   {
      $seconds   = (((time() - $urtime) / 1) % 60);
      $minutes   = (intval((time() - $urtime) / 60) % 60);
      $hours      = intval((time() - $urtime) / 3600);
      $days      = intval((time() - $urtime) / 86400);
      $weeks      = intval((time() - $urtime) / 604800);
      $months      = intval((time() - $urtime) / 2419200);
      $years      = intval((time() - $urtime) / 29030400);
      $result      = array();
      $result['years']   = ($years) ? sprintf('%u year%s,', number_format($years), ($years > 1) ? 's' : '') : FALSE;
      $result['months']   = ($months) ? sprintf('%u month%s,', number_format($months), ($months > 1) ? 's' : '') : FALSE;
      $result['weeks']   = ($weeks) ? sprintf('%u week%s,', number_format($weeks), ($weeks > 1) ? 's' : '') : FALSE;
      $result['days']   = ($days) ? sprintf('%u day%s,', number_format($days), ($days > 1) ? 's' : '') : FALSE;
      $result['hours']   = ($hours) ? sprintf('%u hour%s,', number_format($hours), ($hours > 1) ? 's' : '') : FALSE;
      $result['minutes']   = ($minutes) ? sprintf('%u minute%s', $minutes, ($minutes > 1) ? 's' : FALSE) : FALSE;
      $result['seconds']   = ($seconds) ? sprintf('%s %u second%s',($minutes) ? 'and' : '', $seconds, ($seconds > 1) ? 's' : FALSE) : FALSE;
      return (count($result) == 0) ? 'Never' : implode(' ', $result).' ago';
   }
?>

 

can anyone help me change this code, so if seconds is <= 1 then it will echo "NOW!"

Link to comment
Share on other sites

<?php
function timeSince($urtime)
   {
      $seconds   = (((time() - $urtime) / 1) % 60);
      $minutes   = (intval((time() - $urtime) / 60) % 60);
      $hours      = intval((time() - $urtime) / 3600);
      $days      = intval((time() - $urtime) / 86400);
      $weeks      = intval((time() - $urtime) / 604800);
      $months      = intval((time() - $urtime) / 2419200);
      $years      = intval((time() - $urtime) / 29030400);
      $result      = array();
      $result['years']   = ($years) ? sprintf('%u year%s,', number_format($years), ($years > 1) ? 's' : '') : FALSE;
      $result['months']   = ($months) ? sprintf('%u month%s,', number_format($months), ($months > 1) ? 's' : '') : FALSE;
      $result['weeks']   = ($weeks) ? sprintf('%u week%s,', number_format($weeks), ($weeks > 1) ? 's' : '') : FALSE;
      $result['days']   = ($days) ? sprintf('%u day%s,', number_format($days), ($days > 1) ? 's' : '') : FALSE;
      $result['hours']   = ($hours) ? sprintf('%u hour%s,', number_format($hours), ($hours > 1) ? 's' : '') : FALSE;
      $result['minutes']   = ($minutes) ? sprintf('%u minute%s', $minutes, ($minutes > 1) ? 's' : FALSE) : FALSE;
      $result['seconds']   = ($seconds) ? sprintf('%s %u second%s',($minutes) ? 'and' : '', $seconds, ($seconds > 1) ? 's' : FALSE) : FALSE;
      if ($seconds <= 1) return "NOW!";
      else return (count($result) == 0) ? 'Never' : implode(' ', $result).' ago';
   }
?>

 

Like that?

Link to comment
Share on other sites

yes thank you ken that worked :D

 

but I have just come across a different error now.

 

its displaying things like

 

"1 day, 31 hours, 56 minutes and 33 seconds ago"

 

why is it display 31 hours?

there's only 24 hours in a day

 

EDIT: and another error, if the user have never logged in... then it will echo NOW instead of never

Link to comment
Share on other sites

a problem is for some reason the second i log in, it starts going up, even when i am still actively clicking links and refreshing pages etc.

Well that's what it should do. The function is called timeSince, so it only makes sense for it to go up. :D

Link to comment
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.