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'
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
The SQL databases on the Azure
cloud are pegged against Greenwich Mean Time(GMT) or Coordinated Universal Time(UTC)
however many applications are using DateTime.Now
which is the time according to the regional settings specified on the host machine.
Sometimes this is not an issue when the DateTime is not used for any time spanning or comparisons and instead for display only. However if you migrate an existing Database to SQL Azure using the dates populated via GETDATE()
or DateTime.Now
you will have an offset, in your case it’s 7 hours during Daylight Saving Time or 8 hours during Standard Time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With