Jump to content

$last->active / time() help.


seany123

Recommended Posts

okay i have this code....

 

<?php 
if ($profile['last_active'] >= Time()-1200)
{
echo "NOW!";
}
else
{
echo date("F j, Y, g:i a", $profile['last_active']);
}
?>

 

instead of the

 

echo date("F j, Y, g:i a", $profile['last_active']);

 

i want it to instead to show minutes since last active..

 

both last->active and time() are big long numbers and i just cant figure out how to make them show the real values.

 

for example i want it to say like:

 

last active: 3 days, 42mins and 30 seconds...

 

all help would be great!

 

Seany

Link to comment
https://forums.phpfreaks.com/topic/151959-last-active-time-help/
Share on other sites

Funny, just posted this else where. But it works for here too:

 

Found this little snippet

 

function search($session_time)
{
//$session_time ="1151348975";

echo"You Entered: $session_time <BR>";
echo"The Current Time is = ".time()."<BR>";
$time_difference = time() - $session_time ;
echo"time_difference = ".$time_difference."<HR>";
$seconds = $time_difference ;
$minutes = round($time_difference / 60 );
$hours = round($time_difference / 3600 );
$days = round($time_difference / 86400 );
$weeks = round($time_difference / 604800 );
$months = round($time_difference / 2419200 );
$years = round($time_difference / 29030400 );
echo"seconds: $seconds<br>";
echo"minutes: $minutes<br>";
echo"hours: $hours<br>";
echo"days: $days<br>";
echo"weeks: $weeks<br>";
echo"months: $months<br>";
echo"years: $years<br>";
} 

 

From: http://www.wallpaperama.com/forums/learn-php-time-function-to-display-time-hours-days-weeks-months-years-t1033.html

 

Hopefully that helps ya out.

echo timeSince($profile['last_active']);

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';
   }

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.