|
這個取服務器時間是通用的,不需要平臺。里面的連接服務器sql server的參數(shù)改成你自己的相關內(nèi)容即可
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
'請修改這個內(nèi)容為你的sql server服務器的相關數(shù)據(jù)
strServer = "localhost" '服務器名稱或IP
strDatabase = "Data" '數(shù)據(jù)庫名
strUser = "sa" '數(shù)據(jù)庫用戶名
strPassword = "123" '數(shù)據(jù)庫密碼
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
|
|