简体   繁体   中英

Time zone name in SQL Server 2008

Is it possible to get the name of the current time zone, such as "Eastern Standard Time" or "EST" in SQL code on SQL Server 2008 R2 ? I know I can determine numeric local time offset by calculating difference between getdate() and getutcdate() , but that's not what I need. I simply need TZ name from the underlying operating system.

Without any defined table, if you just want to read the time zone information from the System Information, then it can be read from the system registry.

declare @TZName varchar(50)

exec master.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
'SYSTEM\CurrentControlSet\Control\TimeZoneInformation',
'TimeZoneKeyName',@TZName OUT

select @TZName

Raj

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM