Reputation: 31
When I execute a select with SYSDATETIME()
it gives me date two days in the past! Three of the date functions give me dates in the past and three give me the correct date. See below.
SELECT SYSDATETIME(),
SYSDATETIMEOFFSET(),
SYSUTCDATETIME(),
CURRENT_TIMESTAMP,
GETDATE(),
GETUTCDATE()
==================================
2011-10-17 10:41:00.4521484
2011-10-17 10:41:00.4521484 -04:00
2011-10-17 14:41:00.4521484
2011-10-19 10:41:00.447
2011-10-19 10:41:00.447
2011-10-19 14:41:00.45
I am using MS SQLServer 2008 and the JDBC 3.0 driver:
DatabaseProductName: MICROSOFT SQL SERVER
DriverName: Microsoft SQL Server JDBC Driver 3.0
getDatabaseProductName: Microsoft SQL Server
getDatabaseProductVersion: 10.50.1600
getDriverVersion: 3.0.1301.101
getDriverMajorVersion: 3
getDriverMinorVersion: 0
getDriverName: Microsoft SQL Server JDBC Driver 3.0
Any ideas what is going on here?
Upvotes: 3
Views: 7386
Reputation: 56
The Microsoft JDBC Driver for SQL Server does not support JRE 1.7. I faced same issue while working with MSSQL server and JRE-1.7. Use hot fix(worked for me) released by Microsoft to resolve your issue.
The hotfix is now available. http://blogs.msdn.com/b/jdbcteam/archive/2012/01/20/hotfix-available-for-date-issue-when-using-jre-1-7.aspx
Please use compatibility information from above article and install appropriate fix according to your Application.
Hope This helps :) Cheers
Upvotes: 3
Reputation: 2475
Our solution to this problem was to switch to sqljdbc4-4.0.jar.
Upvotes: 0
Reputation: 11
We ran into this same problem and was able to fix it by falling back from Java 1.7 SDK to Java 1.6 (but not the _30 version, which has problems).
Upvotes: 0
Reputation: 2221
First three functions in your query SYSDATETIME(),SYSDATETIMEOFFSET(),SYSUTCDATETIME()
take the date and time of the computer on which the instance of SQL Server is running.
And the last three CURRENT_TIMESTAMP,GETDATE(),GETUTCDATE()
take date & time from the operating system of the computer on which the instance of SQL Server is running.
Upvotes: 1