|
这个取服务器时间是通用的,不需要平台。里面的连接服务器sql server的参数改成你自己的相关内容即可
Public Function gf_GetServerTime() As Date '获得SQL SERVER服务器时间
On Error GoTo Err_Hanlder
Dim rst As Object
Dim cn As Object
Dim strServer As String
Dim strDatabase As String
Dim strUser As String
Dim strPassword As String
Dim strMachine As String
'请修改这个内容为你的sql server服务器的相关数据
strServer = "localhost" '服务器名称或IP
strDatabase = "Data" '数据库名
strUser = "sa" '数据库用户名
strPassword = "123" '数据库密码
Set cn = CreateObject("ADODB.Connection")
cn.Open "DRIVER={SQL Server};SERVER=" & strServer & ";UID=" & strUser & ";PWD=" & strPassword & ";DATABASE=" & strDatabase
Set rst = CreateObject("ADODB.Recordset")
rst.Open "Select GETDATE() AS FSqlCurrDate", cn, 1, 3
If Not rst.EOF Then gf_GetServerTime = rst(0)
Exit_Hanlder:
On Error Resume Next
rst.Close
cn.Close
Set rst = Nothing
Set cn = Nothing
Exit Function
Err_Hanlder:
MsgBox Err.Description
GoTo Exit_Hanlder
End Function
|
|