I thought I would pass along one solution to a requirement that surfaced recently: suppose you need to know if a user has visited a page on your site within the last four weeks at login, and if not, remind them what a wonderful page it is.

You can accomplish exactly that by calling the following function from hook_login():


 * Check if a site url has been visited in a specified interval.
 * @param $uid The user ID of the user to check.
 *   Example: 200
 * @param $path The internal Drupal path.
 *   Example: 'node/1' or 'mypage'
 * @param $interval An interval MySQL understands
 *   Example: '5 DAY' or '5 WEEK' (note value is not plural)
function check_page_visited_in_time_interval ($uid, $path, $interval) {
  if (
module_exists('statistics')) {
// Original SQL
$sql = 'SELECT timestamp FROM `accesslog`
            WHERE uid = $uid
            AND path = $path
            AND `timestamp` > UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL $interval));'

$date = date_create();
date_modify($date, '-'.$interval);
$interval $date->format('U');

$result = db_query("
    SELECT timestamp
    FROM accesslog
    WHERE uid = :uid
    AND path = :path
    AND timestamp > :interval"
$result as $r) {
$time[$r->timestamp] = $r->timestamp;
$rowcount = count($time);
    if (
$rowcount > 0) {