You are here

function visitors_mysql_date_format_sql in Visitors 7.2

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

Set date format for mysql sql query.

Parameters

$field_name string field name:

$format string date format:

Return value

string date format

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

File

./visitors.module, line 313

Code

function visitors_mysql_date_format_sql($field_name, $format) {
  $mysql_current_timezone = visitors_get_mysql_current_timezone();
  $diff = visitors_timezone_diff();
  $timezone = (int) ($diff / 60 / 60);
  $timezone .= sprintf(':%02d', abs($diff) / 60 % 60);
  if ($timezone >= 0) {
    $timezone = '+' . $timezone;
  }
  return sprintf("date_format(convert_tz(from_unixtime(%s), '%s', '%s'), '%s')", $field_name, $mysql_current_timezone, $timezone, $format);
}