SQL GetDate () returns wrong time

I am having a problem when using it GetDate()

, for some reason it does not return at the right time (this is 7 hours ahead of the actual time) I am using AZURE

and the database is configured with the correct location (West US). I would appreciate any help!

I tried to run this script:

SELECT id,
       status,
       AcceptedDate,
       Getdate(),
       Datediff(hour, AcceptedDate, Getdate())
FROM   orderoffers
WHERE  status = 'Accepted' 

      

+3


source to share


2 answers


Azure SQL Databases are always UTC, regardless of the datacenter. You will want to handle the timezone change in your application.

In this case, since you want to compare "now" with the data column, make sure AcceptedDate

to store it in UTC as well.



Link

+8


source


SQL databases in the cloud are Azure

tied to Greenwich Mean Time(GMT) or Coordinated Universal Time(UTC)

, but in many applications is used DateTime.Now

, which is the time according to the regional settings specified on the host computer.



Sometimes this is not a problem when DateTime is not used for any time, nor for comparison, but for display only. However, if you are migrating an existing database to SQL Azure using dates populated with GETDATE()

or DateTime.Now

, you will have an offset, in your case 7 hours during daylight saving time or 8 hours during standard time.

+2


source







All Articles