Use the at time zone operator to convert between timestamp and timestamp with time zone values. Specify the time zone as a name or as a UTC offset interval.
Operation
Return Type
Example
timestamp at time zone 'timezone'
timestamptz
timestamp '2001-08-16 20:38:40' at time zone 'Europe/Berlin' → 2001-08-16 18:38:40+00 (assumes the default time zone is UTC)
timestamptz at time zone 'timezone'
timestamp
timestamptz '2001-08-16 18:38:40+00' at time zone 'Europe/Berlin' → 2001-08-16 20:38:40
timestamp at time zone interval 'interval'
timestamptz
timestamp '2001-08-16 20:38:40' at time zone interval '+2:00' → 2001-08-16 18:38:40+00 (assumes the default time zone is UTC)
timestamptz at time zone interval 'interval'
timestamp
timestamptz '2001-08-16 18:38:40+00' at time zone interval '+2:00' → 2001-08-16 20:38:40
Considerations
Data 360 SQL outputs interval data in the ISO-8601 style. For example, P1DT2H3M4S corresponds to 1 day, 2 hours, 3 minutes, and 4 seconds.
To find the number of seconds between two timestamps and adjust for month lengths, time zone changes, and daylight saving time, use EXTRACT(EPOCH FROM ...) on each value and subtract the results. The - operator makes the same adjustments but returns the result as an interval of days, hours, minutes, and seconds.
These queries show the difference between the two approaches. The samples use timezone = 'US/Eastern' and span a daylight saving time change.
1SELECT EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') -2EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00');3Result: 1053720045SELECT(EXTRACT(EPOCH FROM timestamptz '2013-07-01 12:00:00') -6EXTRACT(EPOCH FROM timestamptz '2013-03-01 12:00:00'))7/ 60 / 60 / 24;8Result: 121.958333333333910SELECT timestamptz '2013-07-01 12:00:00' - timestamptz '2013-03-01 12:00:00';11Result: 121 days 23:00:00