database - 在 Access 中的天数后用 'nd' 或 'th' 格式化日期

标签 database date ms-access format ms-access-2007

我正在为 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/

相关文章:

java - 安卓日期范围

SQL 字符串比较忽略空格

csv - 检查 csv 文件是否从 vba 打开

database - 没有属性的 WCF 服务返回对象

sql - 如何将 db 对象数据类型从 varchar 更改为 nvarchar 而不默认为 null?

database - SQL Server AUTO_INCREMENT 错误

java - 使用 UCanAccess 查询 Access 数据库时的正则表达式匹配

python - Django 保存空白值

javascript - Moment JS持续时间人性化更精确

javascript - 为什么 Javascript 日期对象中的 0 月是 1 月,而年、日、小时……开始是 1?