I'm trying to update a database field to the current time, but can't pass "now()". I get the following error:
'`now`' is not a recognized built-in function name.
The method I'm using to query the database is as follows:
Public Sub main()
Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.Open "ConnectionName"
rst.ActiveConnection = cnn
rst.CursorLocation = adUseServer
rst.Source = "Update Table ..."
rst.Open
Set rst = Nothing
Set cnn = Nothing
End Sub
Now()
is a VBA function. What you want to do is use the equivalent SQL function, but that depends on the database that you're connecting to.
If it's SQL Server you're connecting to, use GETDATE()
(for local times) or GETUTCDATE()
(for UTC times).
尝试getdate()函数或CURRENT_TIMESTAMP
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.