My server is hosted in US or so with some other time zone. Is there an option to get the current date in SQL Server in Indian Standard Time.
select getdate()
What should I write to get the current time in India(or some other country as such).
My server is hosted in US or so with some other time zone. Is there an option to get the current date in SQL Server in Indian Standard Time.
select getdate()
What should I write to get the current time in India(or some other country as such).
You should use the DATETIMEOFFSET
datatype which includes the timezone, and the SWITCHOFFSET
method to switch between timezones. Also: to get the current time, use SYSDATETIMEOFFSET()
instead of GETDATE()
-- gets current date/time in the current timezone
SELECT
SYSDATETIMEOFFSET()
-- get the current date/time in your preferred timezone +05:30 UTC being Indian Std. Time
SELECT
SWITCHOFFSET(SYSDATETIMEOFFSET(), '+05:30')
According to this link India's time is 9:30 hours ahead
from US. So in-order to get the Indian time, you need to add 9.30 hours
to US time.
SELECT DATEADD(hh,9.30,getdate())