标题: 请问当月的第一天的表达式怎么写? [打印本页] 作者: 徐阿鹏 时间: 2003-5-13 04:01 标题: 请问当月的第一天的表达式怎么写? 请问当月的第一天的表达式怎么写?vba?
最后一天怎么写?
谢谢!作者: skylark 时间: 2003-5-13 04:47
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作者: eio 时间: 2003-5-13 04:54
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 & "”。"作者: eio 时间: 2003-5-13 04:58
再简化:
MsgBox DateSerial(Year(Now), Month(Now), 1)