Inserting current DateTime into Audit table

后端 未结 2 1084
南方客
南方客 2020-12-21 10:06

I am in the process of implementing an audit log to record a brief description of changes to the database. My audits table consists of an autonumber PK, emp

相关标签:
2条回答
  • 2020-12-21 10:18

    Try it this way.

    strQuery = "INSERT INTO Audits ([emp Number], [Description], dateofAudit)" & _
        vbCrLf & "VALUES (" & Me.empID & ", 'insertion', Now())"
    

    Also give yourself an opportunity to examine the finished text string.

    Debug.Print strQuery 
    

    With that approach, you wouldn't need your currDateTime variable. The Date/Time value would be determined when the db engine evaluates the Now() function ... the time at which the INSERT statement is executed.

    If you want the time as per your original approach, format currDateTime and add # delimiters.

    strQuery = "INSERT INTO Audits ([emp Number], [Description], dateofAudit)" & _
        vbCrLf & "VALUES (" & Me.empID & ", 'insertion', " & _
        Format(currDateTime, "\#yyyy-mm-dd hh:nn:ss\#") & ")"
    
    0 讨论(0)
  • 2020-12-21 10:23

    try to format datetime like this:

    protected DateTime GetDateWithoutMilliseconds(DateTime d)
        {
            return new DateTime(d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second);
        }
    
    0 讨论(0)
提交回复
热议问题