设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 1449|回复: 3
打印 上一主题 下一主题

[报表] 请问当月的第一天的表达式怎么写?

[复制链接]
跳转到指定楼层
1#
发表于 2003-5-13 04:01:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
请问当月的第一天的表达式怎么写?vba?
最后一天怎么写?
谢谢!
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
发表于 2003-5-13 04:47:00 | 只看该作者
To  徐阿鹏:
Function FirstOfMonth(InputDate As Date)
'  Return a date that is the first day of the month of the date passed
Dim D As Integer, M As Integer, Y As Integer

    If IsNull(InputDate) Then
        FirstOfMonth = Null
    Else
        D = Day(InputDate)
        M = Month(InputDate)
        Y = Year(InputDate)
        FirstOfMonth = DateSerial(Y, M, 1)
    End If
End Function

Function LastOfMonth(InputDate As Date)
'  Return a date that is the last day of the month of the date passed
Dim D As Integer, M As Integer, Y As Integer
   
    If IsNull(InputDate) Then
        LastOfMonth = Null
    Else
        D = Day(InputDate)
        M = Month(InputDate)
        Y = Year(InputDate)
        'find the first day of next month, then back up one day
        LastOfMonth = DateAdd("m", 1, DateSerial(Y, M, 1)) - 1
    End If
End Function
第一天   =firstofmonth(Now())
最后一天  =lastofmonth(Now())
_______________________________
Do Our Job Well   Try Anything Once
3#
发表于 2003-5-13 04:54:00 | 只看该作者
Dim first, last As Date
first = Date - Format(Date, "dd") + 1
MsgBox "今日是“" & Date & "”。"
MsgBox "本月第一日是“" & first & "”。"
last = DateSerial(Year(Now), Month(Now) + 1, 1) - 1
MsgBox "本月最后一日是“" & last & "”。"
4#
发表于 2003-5-13 04:58:00 | 只看该作者
再简化:
MsgBox DateSerial(Year(Now), Month(Now), 1)

MsgBox DateSerial(Year(Now), Month(Now) + 1, 1) - 1
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

GMT+8, 2024-5-12 07:43 , Processed in 0.074138 second(s), 27 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表