Calling all Drupal developers!
Help us get this on the first page of Digg. DIGG NOW!
Help us get this on the first page of Digg. DIGG NOW!
views_date_sql_field($field, $field_type = 'int', $set_offset = NULL)
contributions/views/includes/handlers.inc, line 833
Helper function to create cross-database SQL dates.
$field The real table and field name, like 'tablename.fieldname'.
$field_type The type of date field, 'int' or 'datetime'.
$set_offset The name of a field that holds the timezone offset or a fixed timezone offset value. If not provided, the normal Drupal timezone handling will be used, i.e. $set_offset = 0 will make no timezone adjustment.
An appropriate SQL string for the db type and field type.
<?php
function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) {
$db_type = $GLOBALS['db_type'];
$offset = $set_offset !== NULL ? $set_offset : views_get_timezone();
switch ($db_type) {
case 'mysql':
case 'mysqli':
switch ($field_type) {
case 'int':
$field = "FROM_UNIXTIME($field)";
break;
case 'datetime':
break;
}
if (!empty($offset)) {
$field = "($field + INTERVAL $offset SECOND)";
}
return $field;
case 'pgsql':
switch ($field_type) {
case 'int':
$field = "$field::ABSTIME";
break;
case 'datetime':
break;
}
if (!empty($offset)) {
$field = "($field + INTERVAL '$offset SECONDS')";
}
return $field;
}
}
?>