Sleek Interactive
4159 Enquist Rd
Campbell River, BC V9H 1A4

OFFICE: 778 420 3918
MOBILE: 250 204 6475

Recent Blog Posts

*content_window*

Reserved words in Javascript "Content_Window" is not the only match in this case....

September 19th, 2011

scrollup(),scrolldown() is not a function

Odd Javascript behaviour scrollup(),scrolldown() is not a function - possible reserved words...

August 31st, 2011

CSS !important

Using !important with inline styles

August 28th, 2011

Custom CSS Cursors

Learn how to add custom cursors to any CSS element in your website....

August 23rd, 2011

Social Networking Timestamp Operator

Learn to create a Timestamp Operator in PHP using the PHP Date function...

August 23rd, 2011

Blog Posts » PHP »

Social Networking Timestamp Operator


BLOG CATEGORY: PHP | Permalink | Posted on: August 23rd, 2011

More and more you see Websites adopting the use of "Standard Social Network Time" or "Less than a minute ago". 

It is a lot easier to understand this type of timestamp lingo than check the date and time. It is displaying dynamic data, which makes it a lot more exciting than just having a static date.

I have written a really simple version of a timestamp operator function here:

function lingo_me_timestamp($timestamp){

$ago = time() - strtotime($timestamp);

if($ago < 60){

$output = "Less than a minute ago";

} else if($ago < 3600){

$output = "Less than an hour ago";

} else if($ago < 86400){

$output = "Today";

} else {

$output = "Posted on: " . date("F jS, Y", strtotime($timestamp));

}

return $output;

}

You can adjust times and messages. The more options you have in the function, the more dynamic your date fields end up being.

Close External Browser Window