SQL Server中IST中的日期 [英] Date in IST in SQL Server

查看:77
本文介绍了SQL Server中IST中的日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器托管在美国或其他时区。是否可以选择以印度标准时间获取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).

推荐答案

您应使用 DATETIMEOFFSET 数据类型,其中包括时区和 SWITCHOFFSET 方法可在时区之间进行切换。另外:要获取当前时间,请使用 SYSDATETIMEOFFSET()代替 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')

这篇关于SQL Server中IST中的日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆