Akhil K Nambiar
Akhil K Nambiar

Reputation: 3975

Date in IST in SQL Server

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).

Upvotes: 5

Views: 29172

Answers (2)

marc_s
marc_s

Reputation: 754508

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')

Upvotes: 22

NaveenBhat
NaveenBhat

Reputation: 3318

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())

Upvotes: 0

Related Questions