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'
source to share
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.
source to share