Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Other SQL Server 2008 Topics
 SYSDATETIME returns wrong date!

Author  Topic 

SamSquanch
Starting Member

1 Post

Posted - 2011-10-19 : 11:06:23
When I execute a select with SYSDATETIME() it gives me date 2 days in the past!!! 3 of the date functions gives me dates in the past and 3 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?

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-10-19 : 11:32:10
My guess is the JDBC driver does not recognize or correctly interpret the SYSDATE functions. I get correct results using SSMS on the same version of SQL Server.
Go to Top of Page

paultech
Yak Posting Veteran

79 Posts

Posted - 2011-10-20 : 10:41:40
Hello i suggest you to use:
SQL Server 2008 obtains the date and time values by using the GetSystemTimeAsFileTime() Windows API. The accuracy depends on the computer hardware and version of Windows on which the instance of SQL Server is running. The precision of this API is fixed at 100 nanoseconds. The accuracy can be determined by using the GetSystemTimeAdjustment() Windows API.

Go to Top of Page
   

- Advertisement -