设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

求某月的最后一天的函数

1970-1-1 08:00| 发布者: 朱亦文| 查看: 758| 评论: 0

由于每个月的天数是不一样的,因此每个月最后一天的日期也不固定的,因此本函数通过循环,判断是否出现新的月份,来确定该月的最后一日的日期.

Public Function MonLastDay(dFirst As Date) As Date
    Dim dm As Date
    Dim m As Integer
    
    dm = dFirst
    m = Month(dm)
    Do While Month(dm) = m
       dm = dm + 1
    Loop
    MonLastDay = dm - 1
End Function

下面是由ACCESS中国的李啸林版主提供:

Public Function MonLastDay1(dFirst As Date) As Date
   MonLastDay1 = DateAdd("d", -1, CDate(DatePart("yyyy", DateAdd("m", 1, dFirst)) & _
                 "-" & DatePart("m", DateAdd("m", 1, dFirst))))
End Function

下面是由ACCESS中国的AlexLiu提供:

Public Function MonLastDay1(dFirst As Date) As Date
   MonLastDay1 = DateSerial(Year(dFirst), Month(dFirst) + 1, 1) - 1 
End Function

最新评论

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-5-7 11:06 , Processed in 0.078015 second(s), 16 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部