question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Casting timestamps with timezones to varchar changes the time

See original GitHub issue

If I cast a timestamp with timezone to a string it shifts the time by an hour. If I cast a string to a timestamp with timezone it shifts the time in the opposite direction.

It seems to be related to daylight savings. Sao Paulo changed their daylight saving on 4th November. Trying dates after that works fine.

What’s going on?

SELECT
    CAST('2018-10-28 14:44:59.000 America/Sao_Paulo' AS TIMESTAMP WITH TIME ZONE),
    CAST(CAST('2018-10-28 14:44:59.000 America/Sao_Paulo' AS TIMESTAMP WITH TIME ZONE) AS VARCHAR)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
elonazoulaycommented, Jan 22, 2019

Reopening this issue as we removed the joda-to-java-time-bridge registration until the cache thrashing issue is resolved.

1reaction
haozhuncommented, Nov 8, 2018

According to tzdata, America/Sao_Paulo zone went through rule changes since 2017b.

# From Steffen Thorsen (2017-12-18):
# According to many media sources, next year's DST start in Brazil will move to
# the first Sunday of November, and it will stay like that for the years after.
# ... https://www.timeanddate.com/news/time/brazil-delays-dst-2018.html
# From Steffen Thorsen (2017-12-20):
# http://www.planalto.gov.br/ccivil_03/_ato2015-2018/2017/decreto/D9242.htm
#
# From Fábio Gomes (2018-10-04):
# The Brazilian president just announced a new change on this year DST.
# It was scheduled to start on November 4th and it was changed to November 18th.
# From Rodrigo Brüning Wessler (2018-10-15):
# The Brazilian government just announced that the change in DST was
# canceled....  Maybe the president Michel Temer also woke up one hour
# earlier today. :)
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to convert a timestamp varchar that contains a timezone ...
Simply cast it into timestamp with time zone (= timestamptz ) type: ... If you want to convert it into a timestamp at...
Read more >
AT TIME ZONE (Transact-SQL) - SQL Server - Microsoft Learn
AT TIME ZONE applies specific rules for converting input values in smalldatetime, datetime, and datetime2 data types that fall into an ...
Read more >
TIMESTAMP WITH TIME ZONE Data Type - Teradata Database
Teradata Database performs implicit conversion from CHARACTER to TIMESTAMP WITH TIME ZONE types during assignment and comparison. This ...
Read more >
4 Datetime Data Types and Time Zone Support
Insert the same data as a TIMESTAMP WITH TIME ZONE literal. Oracle Database converts the data to a TIMESTAMP WITH LOCAL TIME ZONE...
Read more >
Impala Date and Time Functions
The FROM_TIMESTAMP() function provides a flexible way to convert TIMESTAMP values into arbitrary string formats for reporting purposes. Because Impala ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found