1.20.x date_sql_handler.inc | date_sql_handler::sql_field($field, $offset = NULL, $comp_date = NULL) |
Helper function to create cross-database SQL dates.
Parameters
string $field: The real table and field name, like 'tablename.fieldname' .
string $offset: The name of a field that holds the timezone offset or an offset value. If NULL, the normal Backdrop timezone handling will be used, if $offset = 0 no adjustment will be made.
Return value
string: An appropriate SQL string for the db type and field type.
File
- modules/
date/ views/ date_sql_handler.inc, line 110 - SQL helper for Date API.
Class
- date_sql_handler
- A class to manipulate date SQL.
Code
function sql_field($field, $offset = NULL, $comp_date = NULL) {
if (strtoupper($field) == 'NOW') {
// NOW() will be in UTC since that is what we set the db timezone to.
$this->local_timezone = 'UTC';
return $this->sql_offset('NOW()', $offset);
}
$field = $this->db_connection->dateFieldSql($field, $this->date_type);
// Adjust the resulting value to the right timezone/offset.
return $this->sql_tz($field, $offset, $comp_date);
}