Time zones can be set in Looker, in your database connection settings, to globally ensure that all type: time
dimensions will be converted from a specified time zone into another specified time zone. The Using Time Zone Settings admin tutorial describes the various Looker settings for time zones.
Looker generates SQL that converts dates and times based on the chosen settings:
If desired, time zone conversion can be turned off for a dimension using the convert_tz
parameter:
dimension_group: created {
type: time
timeframes: [time, date]
convert_tz: no
}
Time zone conversion can also be manually defined within a dimension's sql
parameter, using your database dialect's functions for time zone conversion:
dimension: created {
type: time
timeframes: [time, date]
sql: CONVERT_TZ(${TABLE}.created_at,'UTC','PST')
}
MySQL Dialect Notes
MySQL requires a time zone table before the conversion function works. This can be run by an admin. You can read more in the MySQL documentation.
Postgres Dialect Notes
Looker uses the driver setting to select the target time zone. This may affect how queries are processed in SQL Runner as compared with pgAdmin, because Looker will use the current datetime in the time zone selected.