Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 802
user1745679 Avatar asked Jan 25 '13 14:01

user1745679


People also ask

What time zone does SQL Server use?

For SQL Database, the time zone is always set to UTC and CURRENT_TIMEZONE returns the name of the UTC time zone.

How do I change the timezone in SQL Server?

Changing the database timezone SQL Server users typically fetch the local timezone by using the GETDATE() function with insert/update statements or as a default constraint for a datetime column in a select statement.

How does SQL store time zones in database?

SQL Server: Use the DATETIMEOFFSET data type, which can store the timezone of UTC. MySQL: Use the TIMESTAMP data type which can include a timezone component. PostgreSQL: Use the TIMESTAMP WITH TIME ZONE data type as this can store the timezone of UTC.

Does SQL Server datetime have timezone?

A time zone offset specifies the zone offset from UTC for a time or datetime value. The time zone offset can be represented as [+|-] hh:mm: hh is two digits that range from 00 to 14 and represent the number of hours in the time zone offset.


1 Answers

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.

like image 109
Aaron Bertrand Avatar answered Oct 08 '22 17:10

Aaron Bertrand