在 Access 中的天数后使用“nd”或“th”格式化日期

use*_*629 3 database format ms-access date ms-access-2007

我正在打印 Access 2007 报告中事件的菜单卡,希望打印输出底部的事件日期按以下方式格式化:2013 年 12 月 2 日(或 2013 年 12 月 25 日)

有没有办法可以格式化 Access 数据库中的日期字段,以便以这种方式打印出来?

Han*_*sUp 5

不幸的是,VBAFormat函数没有提供您想要的功能。但是,您可以使用自定义 VBA 函数来格式化事件日期的日期部分并添加格式化的月份和年份。

DayString([event date]) & " " & Format([event date], "mmmm, yyyy")
Run Code Online (Sandbox Code Playgroud)

将此函数保存在标准模块中。

Public Function DayString(ByVal pDate As Date) As String
    Dim intDay As Integer
    Dim strReturn As String

    intDay = Day(pDate)
    Select Case intDay
    Case 1, 21, 31
        strReturn = intDay & "st"
    Case 2, 22
        strReturn = intDay & "nd"
    Case 3, 23
        strReturn = intDay & "rd"
    Case Else
        strReturn = intDay & "th"
    End Select
    DayString = strReturn
End Function
Run Code Online (Sandbox Code Playgroud)