Jump to content

Recommended Posts

http://us2.php.net/time

Returns the current time measured in the number of seconds since the Unix Epoch (January 1 1970 00:00:00 GMT).

 

You have two values that represent seconds.  Take the difference and divide by 60 (seconds per minute)...

Thanks, I came up with this:

 

<?php
$postedTime="1192909166";
$nowTime=time();
$diff=$nowTime-$postedTime;


echo "Posted" . $diff . " seconds ago<br>";

echo "Posted " . $diff/60 . " minutes ago<br>";

echo "Posted " . $diff/3600 . " hours ago<br>";

echo "Posted " . $diff/86400 . " days ago<br>";
?>

But if you want exact time.

 

##Last Touch is the last time the person clicked anything
$seconds_ago = time() - $last_touch;

##How many Types of Time should we show?
$list_number = 2;

##Month Check
$months_ago = floor($seconds_ago / 2592000);
if($months_ago > 0) { 
$seconds_left = $seconds_ago - ($months_ago * 2592000); 
$last_active = "$months_ago Months";
$active_length++;
}

##Day Check
$days_ago = floor($seconds_left / 86400);
if($days_ago > 0) { 
$seconds_left = $seconds_left - ($days_ago * 86400); 
if($list_number > $active_length) {
$active_length++;
$last_active .= "$days_ago Days";
}
}

##Hour Check
$hours_ago = floor($seconds_left / 3600);
if($hours_ago > 0) { 
$seconds_left = $seconds_left - ($hours_ago * 3600); 
if($list_number > $active_length) {
$active_length++;
$last_active .= "$hours_ago Hours";
}
}

##Minute Check
$minutes_ago = floor($seconds_left / 60);
if($minutes_ago > 0) { 
$seconds_left = $seconds_left - ($minutes_ago * 60); 
if($list_number > $active_length) {
$active_length++;
$last_active .= "$minutes_ago Minutes";
}
}

##Second Check
if($seconds_left > 0) { 
if($list_number > $active_length) {
$active_length++;
$last_active .= "$seconds_left Seconds";
}
}

 

I just wrote this freehand, not 100% sure it is without flaw.

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.