You are here

function visitors_pgsql_date_format_sql in Visitors 8.2

Same name and namespace in other branches
  1. 8 visitors.module \visitors_pgsql_date_format_sql()
  2. 7.2 visitors.module \visitors_pgsql_date_format_sql()
  3. 7 visitors.module \visitors_pgsql_date_format_sql()
  4. 7.0 visitors.module \visitors_pgsql_date_format_sql()

Set date format for pgsql sql query.

Parameters

$field_name string field name:

$format string date format:

Return value

string date format

1 call to visitors_pgsql_date_format_sql()
visitors_date_format_sql in ./visitors.module
Set date format for sql query.

File

./visitors.module, line 131
Logs visitors for your site.

Code

function visitors_pgsql_date_format_sql($field_name, $format) {
  static $format_array = array(
    '%H' => "to_char(TIMESTAMP 'epoch' + (%s + (%d)) * INTERVAL '1 second', 'HH24')",
    '%a' => "to_char(TIMESTAMP 'epoch' + (%s + (%d)) * INTERVAL '1 second', 'dy')",
    '%w' => "cast(to_char(TIMESTAMP 'epoch' + (%s + (%d)) * INTERVAL '1 second', 'D') as integer) - 1",
    '%d' => "to_char(TIMESTAMP 'epoch' + (%s + (%d)) * INTERVAL '1 second', 'DD')",
    '%Y %M' => "to_char(TIMESTAMP 'epoch' + (%s + (%d)) * INTERVAL '1 second', 'YYYY Month')",
    '%Y%m' => "to_char(TIMESTAMP 'epoch' + (%s + (%d)) * INTERVAL '1 second', 'YYYYMM')",
  );
  if (isset($format_array[$format])) {
    $diff = visitors_timezone_diff();
    $result = sprintf($format_array[$format], $field_name, $diff);
  }
  else {
    $result = '';
  }
  return $result;
}