-
Notifications
You must be signed in to change notification settings - Fork 107
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
dbGet/SendQuery: Dates shifted to day before #293
Comments
It's about the timezone. odbc will always return date/datetime in UTC. (I don't have the access to SQL Server now but I remember the date is converted to strings in R so should not have this issue. ) Anyway, using We are not able to control the returned timezone in odbc for now, which is a bit of inconvinient... Returning UTC based datetime is not what I want usually... I prefer the returned timezone is the same as the server... |
Hi shrektan, I am not sure I understand your answer. My issue concerns the |
(I know why the workaround won't work - odbc has converted to date already...) First of all, on my computer, the However, if it returns a Internally, odbc receives a datetime object first, then mark it as UTC, then converts the datetime object to your timezone, then the date part is extracted from that. Since the datetime object gets converted (from UTC to your timezone), extracting the date part may lead to one-day off from the real value. For example, '2019-01-01' (MSSQL no timezone) -> Line 419 in 24bf73b
So I bet you will get a correct result for date if you provide "UTC" timezone in the connection. con <- DBI::dbConnect(odbc::odbc()
, driver = "ODBC Driver 13 for SQL Server"
, server = <removed>
, trusted_connection = "Yes"
, timezone = "UTC"
) |
@matthijsvanderloos Would you mind test my try-to-fix-this-issue branch? Install it by running: remotes::install_github('shrektan/odbc', ref = 'fix293') Please let me know if it works (sorry that I can't test it in advance because odbc somehow doesn't recongize date as Date on my computer). (Please use Thanks! |
@matthijsvanderloos I just confirmed my patch works (Using |
@shrektan I can confirm that your patch also works on my setup. Thanks! |
Issue Description and Expected Result
When querying date columns from MSSQL dates are shifted to the day before. For example, 2019-01-01 is returned as 2018-12-31 in R. Timestamps are returned OK. When I
unclass()
the returned date it is fractional.I am using the
timezone
argument ofdbConnect()
as the database timezone is set to CET instead of UTC.Might be related to #61 and #95?
Database
Microsoft SQL Server 2017 (RTM-GDR) (KB4505224) - 14.0.2027.2 (X64)
Jun 15 2019 00:26:19
Copyright (C) 2017 Microsoft Corporation
Developer Edition (64-bit) on Windows Server 2012 R2 Standard 6.3 (Build 9600: ) (Hypervisor)
Reproducible Example
Created on 2019-08-23 by the reprex package (v0.3.0)
Session Info
The text was updated successfully, but these errors were encountered: