我正在为 Access 2007 报告中的事件打印菜单卡,希望打印输出底部的事件日期格式如下:2013 年 12 月 2 日(或 2013 年 12 月 25 日)
有没有一种方法可以格式化 Access 数据库中的日期字段,以便以这种方式打印出来?
最佳答案
不幸的是,VBA Format
函数没有提供您想要的功能。但是,您可以使用自定义 VBA 函数来格式化事件日期的日期部分,并添加格式化的月份和年份。
DayString([event date]) & " " & Format([event date], "mmmm, yyyy")
将此函数保存在标准模块中。
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
关于database - 在 Access 中的天数后用 'nd' 或 'th' 格式化日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20380746/