Search code examples
sql-serversql-server-2005

SQL Server Timezone Change


I have 2 databases on the same SQL Server. Is it possible to have one in PST and the other in EST?


Solution

  • No, The date/time is derived from the operating system of the computer on which the instance of SQL Server is running.

    You could however have a custom UDF that you would call instead of getdate() and then do the timezone change in that UDF. You can also assign default values to columns with something like this

    CREATE TABLE Test (Val DATETIME DEFAULT  dateadd(hh,-3,GETDATE()))
    

    Now when you do an insert it will use the default

    INSERT test DEFAULT VALUES
    
    SELECT * FROM test
    

    ....this of course won't work on updates and also someone could update that value

    If you want to use GMT then use GETUTCDATE

    SELECT GETUTCDATE()