But mummy, where does time come from?

  • So ... here I was inserting data from one server into another server, and my insert code contains a GETDATE() column (which I simply use as my RecordInsertedDateTime column for auditing/keep my sanity purposes)

    But where does the time for the GETDATE() function come from? from the time on the 1st server (which is running the job/code) or from the time on the recipient server (which does the actual inserting).

    I hope someone can shine some light on this.

  • It's going to be coming from the server that's running the code.
    You're telling it to execute the function GETDATE() and send the results of that function to the destination.
    Similarly, if you had a function called FOO(), you could reference FOO() on your server where you're running your code without it existing on the target server. It's not telling the target server to run the function FOO() and put the results in the table when you're done.

  • This was removed by the editor as SPAM

  • SQL Server maintains time itself. However, it syncs periodically (every minute or less) with the underlying host OS, which maintains the time based on hardware crystals and optional NTP (network time) servers. When you execute GETDATE(), SQL Server will return the current time, as it sees it. Therefore, time on the server matters. You can also use sysdatetime(), which is a replacement with more precision.

    If I have code on ServerA, which is a batch that is executed on ServerB (say through linked server) ,the batch likely executes on ServerB, which is where the time will come from. The execution context would likely depend on what you're doing, but in general, it's on the server where the code runs. If you share more about the architecture, we can help.

    @steve-2 Summers, not sure what you're referring to as you don't discuss GETDATE().

  • Thanks very much for the replies! @SteveJones,  thanks for the explanation about how sql server deals with time, that explains a few inconsistencies I observed!

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

  • This was removed by the editor as SPAM

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply