Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Implicit cast from datetimeoffset to other date/time datatypes. #2600

Conversation

rohit01010
Copy link
Contributor

Description

Due to implicit cast from datetimeoffset to datetime we are getting wrong output

--- AT TIME ZONE returns datetimeoffset

DECLARE @lvDateEastern DATETIME, @lvDateUTC DATETIME
SET @lvDateUTC = '2021-01-01'
SET @lvDateEastern = @lvDateUTC AT TIME ZONE  'UTC' AT TIME ZONE 'US Eastern Standard Time'
SELECT @lvDateUTC, @lvDateEastern

@lvDateUTC              @lvDateEastern
----------------------- -----------------------
2021-01-01 00:00:00.000 2021-01-01 00:00:00.000

Expected
----------------------- -----------------------
2021-01-01 00:00:00.000 2020-12-31 19:00:00.000 
The above same issue is occuring when we are doing implicit cast from datetimeoffset to time,date,smalldatetime,datetime2.

Fixed this issue by excluding the timezone offset addition/subtraction to the original timestamp .

Cherry-picked from #1927

Authored-by: Ashish Prasad
Signed-off by: Rohit Bhagat [email protected]

Issues Resolved

BABEL-986

Test Scenarios Covered

Use case based -
Added

Boundary conditions -
Added

Arbitrary inputs -
Already present

Negative test cases -
Already present

Minor version upgrade tests -
NA

Major version upgrade tests -
NA

Performance tests -
NA

Tooling impact -
NA

Client tests -
Added

Check List

[x] Commits are signed per the DCO using --signoff
By submitting this pull request, I confirm that my contribution is under the terms of the Apache 2.0 and PostgreSQL licenses, and grant any person obtaining a copy of the contribution permission to relicense all or a portion of my contribution to the PostgreSQL License solely to contribute all or a portion of my contribution to the PostgreSQL open source project.

For more information on following Developer Certificate of Origin and signing off your commits, please check here.

…abelfish-for-postgresql#1927)

Due to implicit cast from datetimeoffset to datetime we are getting wrong output

--- AT TIME ZONE returns datetimeoffset

DECLARE @lvDateEastern DATETIME, @lvDateUTC DATETIME
SET @lvDateUTC = '2021-01-01'
SET @lvDateEastern = @lvDateUTC AT TIME ZONE  'UTC' AT TIME ZONE 'US Eastern Standard Time'
SELECT @lvDateUTC, @lvDateEastern

@lvDateUTC              @lvDateEastern
----------------------- -----------------------
2021-01-01 00:00:00.000 2021-01-01 00:00:00.000

Expected
----------------------- -----------------------
2021-01-01 00:00:00.000 2020-12-31 19:00:00.000
The above same issue is occuring when we are doing implicit cast from datetimeoffset to time,date,smalldatetime,datetime2.

Fixed this issue by excluding the timezone offset addition/subtraction to the original timestamp .

Issues Resolved : BABEL-986
Signed-off-by: Ashish Prasad <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants