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
https://forums.phpfreaks.com/topic/156437-solved-help-with-this-please/
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?

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.