Date in IST in SQL Server

2019-08-10 03:46发布

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

2条回答
该账号已被封号
2楼-- · 2019-08-10 04:29

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())
查看更多
Summer. ? 凉城
3楼-- · 2019-08-10 04:32

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')
查看更多
登录 后发表回答