Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 How can we set the Time Zone of a database permene

Author  Topic 

KCube
Starting Member

2 Posts

Posted - 2008-07-30 : 05:07:11
Hello,
How can we set the Time Zone of a database permenently?

It should work regardless of OS Time Zone.

Any solution for getting different datatime for two different database instance running on same sql server.

Any Solution other than getutcdate() in appreciable

Regards,
KCube

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-30 : 05:30:24
Yes. Write an UDF to return DATETIME.




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-30 : 05:34:09
[code]CREATE FUNCTION dbo.fnMyTimeZone
(
@DbName SYSNAME
)
RETURNS DATETIME
AS
BEGIN
RETURN CASE @DbName
WHEN 'Db1' THEN DATEADD(HOUR, -1, GETDATE())
WHEN 'Db2' THEN DATEADD(HOUR, -3, GETDATE())
ELSE GETDATE()
END
END[/code]Call with
SELECT dbo.fnMyTimeZone(DB_NAME())


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-30 : 05:35:19
Or per server maybe?
CREATE FUNCTION dbo.fnMyTimeZone
(
)
RETURNS DATETIME
AS
BEGIN
RETURN CASE @@SERVERNAME
WHEN 'Server1' THEN DATEADD(HOUR, -1, GETDATE())
WHEN 'Server2' THEN DATEADD(HOUR, -3, GETDATE())
ELSE GETDATE()
END
END



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

KCube
Starting Member

2 Posts

Posted - 2008-07-30 : 23:13:42
Hi,
Thanks very much for the effort. Will it be over burden for the server. Will it affect the performance.

Is there any difference between UDF and buitin function in respect to performance.

I am concern about the performace issues.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-07-31 : 04:31:32
Not much, since the function is written as an inline-function.


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -