Hello...

In SQL, a query like "DELETE FROM [table] WHERE [date field] < (GETDATE
() - 30)" should be more than enough.

You don't need to go as far as providing it a programmatically
computed "currentDateTime".
(Moreover, the .NET "Now.ToString("yyyy/dd/MM hh:mm:ss")" is easier to
write and read.)
Tough, if you really wish to, remember to encase the date in quotes.
" DELETE FROM ... WHERE date < 2009/01/01 " is not recognized;
" DELETE FROM ... WHERE date < '2009/01/01' " is.


Finally, I hope that you do have a relevant datetime field, or a log
table... or that your database stores the insertion/modification date
by default.

On 20 août, 19:06, MM <[email protected]> wrote:
> Hi,
>
> I am trying to delete all entries in a table that are older than 30
> days. Here is my code in VB, can someone tell me how to fix this so
> that it actually does the deletion? thank you
>
> Private Sub clearEventLog()
> Dim sql
> Dim currentDateTime As String
>
> Try
>  currentDateTime = Month(Now()) & "/" & Day(Now()) & "/" & Year(Now())
> & " " & Hour(Now()) & ":" & Minute(Now()) & ":" & Second(Now())
> app.Events.Write("current date: " & currentDateTime)
>             sql = "DELETE FROM TBLAPPLICATIONLOG WHERE DTMERROR < " &
> currentDateTime - 30
>             _dbAccess.executeDbCommand(sql)
>         Catch ex As Exception
>             onError("eventViewer.aspx.vb | clearEventLog() " &
> ex.Message, ex)
>  End Try
>  End Sub

Reply via email to