Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Time zone in SQL Server

Time zone in SQL Server

Scheduled Pinned Locked Moved Database
databasesql-servercomsysadmintutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Goutam Patra
    wrote on last edited by
    #1

    I am onto a project of backoffice management of International stock exchanges. I need to manage trades of different stock exchanges there. The date and time I am getting from exchange is according to their time zone. Further I need to calculate some thing using their time. Some of reports I need to generate after converting the time to my time zone that is IST (I am from India). Now what I have in my mind is to store the time provided by the exchange with the time zone (of the exchange) and also the converted (to IST) time. I am looking for some idea how to store the time zone and the converted time into database. Is there any facility in SQL server to time between time zones or I have to keep the time gap between zones? I have found SQL 2005 Time Zone Conversion Functions[^] and http://msdn.microsoft.com/en-us/library/ms145276%28SQL.90%29.aspx[^] But, what would be the best practice to do such thing?

    L D 2 Replies Last reply
    0
    • G Goutam Patra

      I am onto a project of backoffice management of International stock exchanges. I need to manage trades of different stock exchanges there. The date and time I am getting from exchange is according to their time zone. Further I need to calculate some thing using their time. Some of reports I need to generate after converting the time to my time zone that is IST (I am from India). Now what I have in my mind is to store the time provided by the exchange with the time zone (of the exchange) and also the converted (to IST) time. I am looking for some idea how to store the time zone and the converted time into database. Is there any facility in SQL server to time between time zones or I have to keep the time gap between zones? I have found SQL 2005 Time Zone Conversion Functions[^] and http://msdn.microsoft.com/en-us/library/ms145276%28SQL.90%29.aspx[^] But, what would be the best practice to do such thing?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The best method for dealing with data from different time zones is to store all time values as UTC times (i.e. zone 0). Where necessary keep also a note of the time zone offset for the record, or the particular account customer. You can then calculate time differences in absolute terms when trying to sort transactions into time order etc. When producing reports for consumers you should add their personal time zone offset to the time values, so the consumer sees report data in their own time zone.

      It's time for a new signature.

      G 1 Reply Last reply
      0
      • G Goutam Patra

        I am onto a project of backoffice management of International stock exchanges. I need to manage trades of different stock exchanges there. The date and time I am getting from exchange is according to their time zone. Further I need to calculate some thing using their time. Some of reports I need to generate after converting the time to my time zone that is IST (I am from India). Now what I have in my mind is to store the time provided by the exchange with the time zone (of the exchange) and also the converted (to IST) time. I am looking for some idea how to store the time zone and the converted time into database. Is there any facility in SQL server to time between time zones or I have to keep the time gap between zones? I have found SQL 2005 Time Zone Conversion Functions[^] and http://msdn.microsoft.com/en-us/library/ms145276%28SQL.90%29.aspx[^] But, what would be the best practice to do such thing?

        D Offline
        D Offline
        dan sh
        wrote on last edited by
        #3

        While saving the time from another time zone, just save value returned by GetDate function. It gives current time in the current timezone. In case you are looking for GMT times, use GetUtcDate function.

        G 1 Reply Last reply
        0
        • L Lost User

          The best method for dealing with data from different time zones is to store all time values as UTC times (i.e. zone 0). Where necessary keep also a note of the time zone offset for the record, or the particular account customer. You can then calculate time differences in absolute terms when trying to sort transactions into time order etc. When producing reports for consumers you should add their personal time zone offset to the time values, so the consumer sees report data in their own time zone.

          It's time for a new signature.

          G Offline
          G Offline
          Goutam Patra
          wrote on last edited by
          #4

          Yes I agree. Actually I was in a bit dilemma because I will get the data from exchange side (they are providing flat files) will be in their time zone. So I need to convert it into UTC first. But in some day end calculations I need to use their time also, so in that time I need to convert it again into their time zone. However perhaps I will store it in UTC format ultimately. Thank you Richard

          L 1 Reply Last reply
          0
          • D dan sh

            While saving the time from another time zone, just save value returned by GetDate function. It gives current time in the current timezone. In case you are looking for GMT times, use GetUtcDate function.

            G Offline
            G Offline
            Goutam Patra
            wrote on last edited by
            #5

            Yes thats right. But I dont want to store the current time. I need to use the time provided by the exchange. Thats why I was thinking what to do Thank you nish.

            1 Reply Last reply
            0
            • G Goutam Patra

              Yes I agree. Actually I was in a bit dilemma because I will get the data from exchange side (they are providing flat files) will be in their time zone. So I need to convert it into UTC first. But in some day end calculations I need to use their time also, so in that time I need to convert it again into their time zone. However perhaps I will store it in UTC format ultimately. Thank you Richard

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              As a general rule you should never store times in a localtime format, they should always be stored as UTC values. This allows you to manipulate them in any way necessary, time difference, sorting etc. It is only necessary to convert to localtime when you wish to display it for the end user irrespective of what time zone that user is in.

              It's time for a new signature.

              G 1 Reply Last reply
              0
              • L Lost User

                As a general rule you should never store times in a localtime format, they should always be stored as UTC values. This allows you to manipulate them in any way necessary, time difference, sorting etc. It is only necessary to convert to localtime when you wish to display it for the end user irrespective of what time zone that user is in.

                It's time for a new signature.

                G Offline
                G Offline
                Goutam Patra
                wrote on last edited by
                #7

                OK. thank you.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups