user1745679
user1745679

Reputation: 249

sql server database timezone different from system timezone

Could anyone help me with a sugesstion, how can I implement following stuff:

I have a system A where my sql server is installed.

But I want to have different timezone for my database in sql server not the system A timezone.

Upvotes: 14

Views: 40429

Answers (2)

Serg Shevchenko
Serg Shevchenko

Reputation: 765

I would recommend to use this (EST in this example)

SYSDATETIMEOFFSET() AT TIME ZONE 'Eastern Standard Time' 

This return precise time date with offset for any selected time zone. This approach will not depend on server time zone.

Upvotes: 2

Aaron Bertrand
Aaron Bertrand

Reputation: 280431

SQL Server has no concept of a time zone. It inherits the system time from Windows, and uses that in real time. For example, if you install SQL Server while the system is in one time zone, and you change the server to a different time zone, the next time you call GETDATE() it will reflect the new time zone, not the one that was in use at the time SQL Server was installed.

In this scenario I think you should just always store UTC data (e.g. using GETUTCDATE() instead of GETDATE(). Much easier to convert it later to your desired (or any!) time zone, e.g. .NET has all kinds of built-in functionality to handle this for you.

Upvotes: 13

Related Questions