1 node.module node_last_viewed($nid)

Retrieves the timestamp for the current user's last view of a specified node.


$nid: A node ID.

Return value

If a node has been previously viewed by the user, the timestamp in seconds: of when the last view occurred; otherwise, zero.


core/modules/node/node.module, line 328
The core module that allows content to be submitted to the site.


function node_last_viewed($nid) {
  global $user;
  $history = &backdrop_static(__FUNCTION__, array());

  if (!isset($history[$nid])) {
    $history[$nid] = db_query("SELECT timestamp FROM {history} WHERE uid = :uid AND nid = :nid", array(':uid' => $user->uid, ':nid' => $nid))->fetchObject();

  return (isset($history[$nid]->timestamp) ? $history[$nid]->timestamp : 0);