Jump to content

How to determine "minutes ago"


techiefreak05

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.

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.