4

I have 2 databases on the same SQL Server. Is it possible to have one in PST and the other in EST?

cdub
  • 24,555
  • 57
  • 174
  • 303

2 Answers2

6

No, The date/time is derived from the operating system of the computer on which the instance of SQL Server is running.

You could however have a custom UDF that you would call instead of getdate() and then do the timezone change in that UDF. You can also assign default values to columns with something like this

CREATE TABLE Test (Val DATETIME DEFAULT  dateadd(hh,-3,GETDATE()))

Now when you do an insert it will use the default

INSERT test DEFAULT VALUES

SELECT * FROM test

....this of course won't work on updates and also someone could update that value

If you want to use GMT then use GETUTCDATE

SELECT GETUTCDATE()
SQLMenace
  • 132,095
  • 25
  • 206
  • 225
0

This does not account for daylight savings time. The only way this can be accomplished is by having a table for the time zones as this example. https://github.com/mattjohnsonpint/SqlServerTimeZoneSupport

In newer SQL versions it's a lot easier but in older versions (2014 or older) there is no straightforward way to accomplish this.

Umar AlFarooq
  • 53
  • 1
  • 8