Changing TimeZone of SQL Server

Discussion in 'Databases' started by dmitri, May 21, 2010.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. dmitri

    dmitri DiscountASP.NET Staff

    The timezone on our SQL Servers cannot and should not be changed. Every physical SQL Server has to live in one and only one time zone. It must not return different times to the clients accessing the server from the different time zones. If the conversion needs to be made it must be done at the client, not at the server side. The clients should get the UTC time from the server and convert it to their local time zone. Also, if a client needs to submit its time to the server it should convert this time to UTC before sending it. In most cases, a client will be a web application that talks to the SQL Server. In other words it is the job of the application to adjust to the time zones, not of the SQL Server.

    SQL Server provides the GETUTCDATE function to get UTC time. GETUTCDATE functions returns the datetime type and has the following format:

    GETUTCDATE()

    SQL Server 2008 and up versions have the additional functions to work with UTC format:

    SYSUTCDATETIME()
    SYSDATETIMEOFFSET()


    If you are targeting only a single time zone and want the server to return the time in this particular time zone you can adjust it with DATEADD function provided by SQL Server. Let’s say the SQL Server resides in Los Angeles, but you need to get time in Tokyo. First you need to find out UTC/GMT Offset of the standard time zone in Japan, which is +9 hours. Then the adjusted code to return the current time in Tokyo will be

    DATEADD (hh, +9, GETUTCDATE())

    Please note that it is your responsibility to adjust the code to the proper time zone and daylight saving time rules of the target location.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page