Public Function GetServerTime() As String
Dim rst As ADODB.Recordset
Set rst = New ADODB.Recordset
Dim sql As String
sql = "select getdate() ServerDate"
rst.Open sql, CnnToData, adOpenKeyset, adLockReadOnly, adCmdText
GetServerTime = FormatDateTime(rst!ServerDate, vbShortDate)
rst.Close
Set rst = Nothing
End Function
record.open "select getdate() as da"
If record.State = 0 Then
MsgBox "读取服务器时间时出错!" + Chr(13) + "请与管理员联系!", vbInformation + vbOKOnly, "错误信息"
Else
If Format(Date, "yyyy-mm-dd") <> Format(record!da, "yyyy-mm-dd") Then
If MsgBox("本机系统日期与服务器日期不同!" + Chr(13) + "是否将用服务器日期替换本机系统日期!", vbYesNo + vbInformation, "提示") = vbYes Then
Date = Format(record!da, "yyyy-mm-dd")
Else
MsgBox "调整错误的系统日期后再运行本程序!", vbOKOnly + vbInformation, "提示"
End
End If
End If
End If