如何从sql实例获取客户端系统当前日期时间?

时间:2021-06-30 08:33:10

Sql server getdate() function fetch server current datetime, how can I get client system current datetime from sql server instance?.

sql server getdate()函数获取服务器当前日期时间,如何从sql server实例获取客户端系统当前日期时间?

One of our client using one database for multiple companies operating from different time zones, being a huge database with many tables, procedures, functions and the getdate() function is used as default value for many area.

我们的一个客户端使用一个数据库为多个公司在不同时区运行,是一个包含许多表,过程,函数和getdate()函数的庞大数据库,被用作许多区域的默认值。

2 个解决方案

#1


0  

You can't. The SQL Server doesn't know anything about the time where the client that called it is located.

你不能。 SQL Server不知道调用它的客户端所在的时间。

Consider using getutcdate() instead. Use UTC exclusively in your database, then convert between time zones in the application layer.

考虑使用getutcdate()代替。在数据库中仅使用UTC,然后在应用程序层中的时区之间进行转换。

If you feel you need to convert between time zones in the database itself, you will need a third-party solution, such as my SQL Server Time Zone Support package.

如果您觉得需要在数据库本身的时区之间进行转换,则需要第三方解决方案,例如我的SQL Server时区支持包。

#2


0  

I have same problem. I found this link: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/290a0085-47a5-48ab-9557-1b59ee269a40/call-getdate-from-linked-server?forum=transactsql

我有同样的问题。我找到了这个链接:https://social.msdn.microsoft.com/Forums/sqlserver/en-US/290a0085-47a5-48ab-9557-1b59ee269a40/call-getdate-from-linked-server?forum=transactsql

declare @rmt_time datetime;
exec('SET ? = CURRENT_TIMESTAMP', @rmt_time OUTPUT) at [remote_server];
select CURRENT_TIMESTAMP as local_time, @rmt_time as rmt_time;

Hope this helps.

希望这可以帮助。

#1


0  

You can't. The SQL Server doesn't know anything about the time where the client that called it is located.

你不能。 SQL Server不知道调用它的客户端所在的时间。

Consider using getutcdate() instead. Use UTC exclusively in your database, then convert between time zones in the application layer.

考虑使用getutcdate()代替。在数据库中仅使用UTC,然后在应用程序层中的时区之间进行转换。

If you feel you need to convert between time zones in the database itself, you will need a third-party solution, such as my SQL Server Time Zone Support package.

如果您觉得需要在数据库本身的时区之间进行转换,则需要第三方解决方案,例如我的SQL Server时区支持包。

#2


0  

I have same problem. I found this link: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/290a0085-47a5-48ab-9557-1b59ee269a40/call-getdate-from-linked-server?forum=transactsql

我有同样的问题。我找到了这个链接:https://social.msdn.microsoft.com/Forums/sqlserver/en-US/290a0085-47a5-48ab-9557-1b59ee269a40/call-getdate-from-linked-server?forum=transactsql

declare @rmt_time datetime;
exec('SET ? = CURRENT_TIMESTAMP', @rmt_time OUTPUT) at [remote_server];
select CURRENT_TIMESTAMP as local_time, @rmt_time as rmt_time;

Hope this helps.

希望这可以帮助。