Adewale George
Adewale George

Reputation: 279

How to get post time stamp on Social Engine

Hi I am trying to get a user up time stamp in the format of "Last Update: ten minutes ago" or "Last Update: 1 hour ago" or "Last Update: yesterday" or "Last Update: three days ago" etc.

I want to be able to echo out the time stamp. please find what i already have below:

$currentUserID=Engine_Api::_()->user()->getViewer()->getIdentity();
$sSqlInviter="select creation_date  from engine4_core_status where resource_id=".$currentUserID;
$dbInviterSqli=Zend_Db_Table_Abstract::getDefaultAdapter();
$stmtInviter=$dbInviterSqli->query($sSqlInviter);
$rowInviter=$stmtInviter->fetch();
$post_time_count=$rowInviter['creation_date'];
echo $this->timestamp($post_time_count); 

but it starts counting from when i refresh the page.

Thanks in advance

I have been able to resolve this too..

$sSqlInviter="select creation_date  from engine4_core_status where resource_id=".$currentUserID." order by creation_date desc limit 1";

Thanks

Upvotes: 1

Views: 592

Answers (1)

Kirk Hammett
Kirk Hammett

Reputation: 676

Looks like you've got the time from your db, but the problem is how to use it right considering the timezone. You can try to use parts of this code:

$oldTz = date_default_timezone_get();               // get old timezone
date_default_timezone_set($viewer->timezone);       // temporarily set user's timezone as default
$start = strtotime($starttime);                     // do something you need
date_default_timezone_set($oldTz);                  // set default timezone back for the rest part of controller
$starttime = date('Y-m-d H:i:s', $start);           // use existing data 

Hope this helps.

Upvotes: 1

Related Questions