1 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
- core/
modules/ date/ views/ date_sql_handler.inc, line 131 - 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);
}
switch ($this->date_type) {
case DATE_UNIX:
$field = "FROM_UNIXTIME($field)";
break;
case DATE_ISO:
$field = "STR_TO_DATE($field, '%Y-%m-%dT%T')";
break;
case DATE_DATETIME:
break;
}
// Adjust the resulting value to the right timezone/offset.
return $this->sql_tz($field, $offset, $comp_date);
}