简体   繁体   English

sql server与不同时区的不同数据库。如何获取所有数据库的getdatetime

[英]sql server with different database of different time zone. how to get getdatetime for all database

I have 4 databases, each in different time zone. 我有4个数据库,每个数据库在不同的时区。
How do I get the date and time of all these with GetDateTime . 如何使用GetDateTime获取所有这些日期和时间。

Usually we get the Server time, but I need the Date and time of the databases 通常我们得到服务器时间,但我需要数据库的日期和时间

If you are using SQL 2008 or later you can take a look on 如果您使用的是SQL 2008或更高版本,则可以查看

SYSDATETIMEOFFSET and SWITCHOFFSET SYSDATETIMEOFFSETSWITCHOFFSET

Generally the first is returning the system datetime with the TimeZone offset part like -07:00 and the second can calculate a time based on datetimeoffset and a timezone offset property. 通常,第一个是使用TimeZone偏移部分返回系统日期时间,如-07:00,第二个可以根据datetimeoffset和时区偏移属性计算时间。

Since there is no database level setting for time-zones you should find an other solution. 由于时区没有数据库级别设置 ,因此您应该找到其他解决方案。

If you would like to manage an application in the same SQL Server but for 4 different database with the correct time-zone for each, I think the best way to make a SystemSetting (the name is not important) table where you can save the offset. 如果您想在同一个SQL Server中管理一个应用程序但是对于每个具有正确时区的4个不同数据库,我认为制作SystemSetting(名称并不重要)表的最佳方法是可以保存偏移量。 Then you can use the SWITCHOFFSET to calculate the correct time for the given database by each query where you need. 然后,您可以使用SWITCHOFFSET根据需要为每个查询计算给定数据库的正确时间。

Or you can try to use virtual-machines. 或者您可以尝试使用虚拟机。

如果这些是SQL 2008服务器或更高版本...

select sysutcdatetime()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM