我有一个带有表Door Activity Log
的.mdb Access数据库。其中有一个名为Door Activity Log Date
的类型为Short Text
的列。当前,其格式为美国日期格式(mm / dd / yyyy)。
我将如何在Access中转换/处理日期(我猜短文本只是字符串),使其变为dd/mm/yyyy
?
答案 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))