Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. SQL Server
  3. Question
SQL Server

SQL server Getutcdate - Why is GETUTCDATE earlier than SYSDATETIMEOFFSET?

Asked by Andrea Bailey Jul 19, 2021 794 views 1 answer
Share

About this question

Let’s consider this Code: 

‘@Offset’ is set before ‘@UTC’, yet it sometimes has a later value. (I've tried this on SQL Server 2008 R2 and SQL Server 2016. One has to run the code a few times to catch the suspect occurrences.)

This does not appear to be simply a matter of rounding or lack of precision. (In fact, I think the rounding is what "fixes" the issue sometimes.) The values for example run are as follows: Offset 2017-06-07 12:01:58.8801139 -05:00UTC 2017-06-07 17:01:58.877 UTC From Offset: 2017-06-07 17:01:58.880

So DateTime precision allows the .880 as a valid value.

Even Microsoft's GETUTCDATE examples show the SYS* values being later than the older methods, despite being SELECTed earlier:

 

 

I presume this is because they come from separate underlying system information. Can anyone confirm and provide details?

Microsoft's SYSDATETIMEOFFSET documentation states "SQL Server obtains the date and time values by using the GetSystemTimeAsFileTime() Windows API" (thanks srutzky), but their GETUTCDATE documentation is much less specific, saying only that the "value is derived from the operating system of the computer on which the instance of SQL Server is running".

 

Your answer

1 Answer

More SQL Server discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest SQL Server Blogs

Guides, tips and career advice on SQL Server from JanBask experts.