Carlos Carlos - 6 months ago 29
SQL Question

SQL GetDate() returns wrong time

I am having an issue while using

GetDate()
, for some reason is not returning the right time (it is 7 hours ahead from the actual time) I am using
AZURE
and the Database is configured with the right location (West US). I will appreciate any help!

I tried to run this script:

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

Answer

Azure SQL Databases are always UTC, regardless of the data center. You'll want to handle time zone conversion at your application.

In this scenario, since you want to compare "now" to a data column, make sure AcceptedDate is also stored in UTC.

Reference

Comments