MS Access-转换短文本的日期格式

时间:2019-05-08 02:15:17

标签: ms-access ms-access-2013

我有一个带有表Door Activity Log的.mdb Access数据库。其中有一个名为Door Activity Log Date的类型为Short Text的列。当前,其格式为美国日期格式(mm / dd / yyyy)。

我将如何在Access中转换/处理日期(我猜短文本只是字符串),使其变为dd/mm/yyyy

2 个答案:

答案 0 :(得分:0)

我用VBA解决了

Private Sub dateFormattingConvert()

Dim rs As DAO.Recordset
Dim oldDate As String
Dim newDate As String
Dim year As String
Dim month As String
Dim day As String
Dim fullString As String
Set rs = CurrentDb.OpenRecordset("Door Activity Log")

If Not (rs.EOF And rs.BOF) Then
    rs.MoveFirst
    Do Until rs.EOF = True
        Debug.Print (rs![Door Activity Log Date])
        oldDate = rs![Door Activity Log Date]
        year = Right(oldDate, 4)
        month = Left(oldDate, 2)
        day = Mid(oldDate, 4, 2)
        fullString = day & "/" & month & "/" & year

        rs.Edit
        rs![Door Activity Log Date] = fullString
        rs.Update

        rs.MoveNext
    Loop
Else
    MsgBox "No more records."
End If

MsgBox "Finished"

rs.Close
Set rs = Nothing

End Sub

答案 1 :(得分:0)

日期应始终存储为日期,而不是文本。

因此,在表 ActivityLogDate 中创建一个新字段,并用如下查询填充它:

Update 
    [Door Activity Log]
Set 
    ActivityLogDate = DateSerial(Mid([Activity Log Date], 7, 4), Mid([Activity Log Date], 1, 2), Mid([Activity Log Date], 4, 2))