[函数]vba计算月初,月末和本月天数
时间:2013-08-16 16:34 来源:Office中国 作者:huanghai 阅读:次
Function firstDayOfMonth(myDate As Date) As Date
firstDayOfMonth = CDate(Format(myDate, "yyyy-m-1"))
End Function
Function lastDayOfMonth(myDate As Date) As Date
lastDayOfMonth = DateAdd("d", -1, DateAdd("M", 1, firstDayOfMonth(myDate)))
End Function
Function DaysInMonth(myDate As Date) As Integer
DaysInMonth = DateDiff("d", firstDayOfMonth(myDate), lastDayOfMonth(myDate)) + 1
End Function
'? firstDayOfMonth("2003-2-4")
' 2003-2-1
'? lastDayOfMonth("2003-2-4")
' 2003-2-28
'? DaysInMonth("2003-2-4")
' 28
firstDayOfMonth = CDate(Format(myDate, "yyyy-m-1"))
End Function
Function lastDayOfMonth(myDate As Date) As Date
lastDayOfMonth = DateAdd("d", -1, DateAdd("M", 1, firstDayOfMonth(myDate)))
End Function
Function DaysInMonth(myDate As Date) As Integer
DaysInMonth = DateDiff("d", firstDayOfMonth(myDate), lastDayOfMonth(myDate)) + 1
End Function
'? firstDayOfMonth("2003-2-4")
' 2003-2-1
'? lastDayOfMonth("2003-2-4")
' 2003-2-28
'? DaysInMonth("2003-2-4")
' 28
(责任编辑:admin)
顶一下
(1)
100%
踩一下
(0)
0%
相关内容
- ·关于 Partition 函数在分组查询中的应
- ·Access算术运算符的含义和说明表
- ·mid函数的另类用法
- ·access制作程序运行进度框
- ·Function与Sub的异同(函数调用)
- ·Access判断某个数值是否为某个数据类型
- ·select case后面语句块的值的四种格式
- ·vba条件语句的两种表示方法
- ·Access几种数据类型初始化的值
- ·Access vba null与""空字符串的区别
- ·access vba 数据类型表
- ·Access变量的命名规则
- ·Access中EXIT Sub与End Sub的区别
- ·Access vba中参数前关键字ByRef和ByVal
- ·Access列表框快速全选的技巧【最快】
- ·vba函数的数据类型强制转换
最新内容
推荐内容