Is it possible to get timezone city information in SQL ? In below format to be precise

Is it possible to get timezone city information in SQL ? In below format to be precise



I want to get the timezone of a machine in the following format using a stored procedure but all I have managed is the UTC+5.30 part yet.



enter image description here



My progress so far:


CREATE PROCEDURE [dbo].[UspGetTimeZone]

AS
SET NOCOUNT ON;


BEGIN

DECLARE @TimeZone VARCHAR(50),
@DetailedTimeZone VARCHAR(50)

set @DetailedTimeZone = (SELECT
SYSDATETIMEOFFSET() AS SYSDATETIMEOFFSET )



DECLARE @CISDB TABLE
(
TimeZone NVARCHAR(100)
)

Insert Into @CISDB( TimeZone)
VALUES ( 'UTC' + (SELECT SUBSTRING(@DetailedTimeZone , 29, 9) AS OFFSET))
select * from @CISDB

END




1 Answer
1



This info is saved into registry,and you can read these data via using xp_regread


xp_regread



so I hope next query helps you:-


CREATE PROCEDURE [dbo].[UspGetTimeZone]
AS
SET NOCOUNT ON;

BEGIN

DECLARE @TimeStandared VARCHAR(50)
EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE',
'SYSTEMCurrentControlSetControlTimeZoneInformation',
'TimeZoneKeyName',@TimeStandared OUT

DECLARE @TimeZone VARCHAR(50),
@keyname varchar(200)
set @keyname = 'SOFTWAREMicrosoftWindows NTCurrentVersionTime Zones' + @TimeStandared
EXEC MASTER.dbo.xp_regread 'HKEY_LOCAL_MACHINE',@keyname, 'Display',@TimeZone OUT
SELECT @TimeZone

END





Thanks @ahmed it works beautifully.
– Pritam Panda
Aug 23 at 11:04






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế