日期函数示例 当天日期:=Date() 当日:=Day(date) 当月:=Month(date()) 当年:=Year(date()) 当季:=DatePart("q",Date()) 把日期大写 Function Date2Chinese(iDate) Dim num(10) Dim iYear Dim iMonth Dim iDay num(0) = "〇" num(1) = "一" num(2) = "二" num(3) = "三" num(4) = "四" num(5) = "五" num(6) = "六" num(7) = "七" num(8) = "八" num(9) = "九" iYear = Year(iDate) iMonth = Month(iDate) iDay = Day(iDate) Date2Chinese = num(iYear \ 1000) + _ num((iYear \ 100) Mod 10) + num((iYear \ 10) Mod 10) + num(iYear Mod 10) + "年" If iMonth >= 10 Then If iMonth = 10 Then Date2Chinese = Date2Chinese +"十" + "月" Else Date2Chinese = Date2Chinese +"十" + num(iMonth Mod 10) + "月" End If Else Date2Chinese = Date2Chinese +num(iMonth Mod 10) + "月" End If If iDay >= 10 Then If iDay = 10 Then Date2Chinese = Date2Chinese +"十" + "日" ElseIf iDay = 20 or iDay = 30 Then Date2Chinese = Date2Chinese + num(iDay \ 10) + "十" + "日" ElseIf iDay > 20 Then Date2Chinese = Date2Chinese + num(iDay \ 10) + "十" + num(iDay Mod 10) + "日" Else Date2Chinese = Date2Chinese + "十" + num(iDay Mod 10) + "日" End If Else Date2Chinese = Date2Chinese + num(iDay Mod 10) + "日" 14 access 与 VBA End If End Function 算出每个月的天数 一法: Dim a, b, c a = Year(Now()) b = Month(Now()) c = Format((a & "/" & b + 1 & "/1"), "######") - Format((a & "/" & b & "/1"), "######") 二法: DateDiff("d", Format(Date, "yyyy-mm-01"), Format(DateAdd("m", -1, Date), "yyyy-mm-01")) DateDiff可以算出两个日期之间相差几天! 三法: Day(DateAdd("d", -1, Format(Date, "yyyy-mm-01"))) day函数可以知道某个日期是这个月的第几天,我们把这个月的最后一天拿出来DAY一下!应该还有更好的方法!比如说可以定义一个数组,把每个月的日子放进去,或者说写一个函数算每一个月的天数只要考虑一下闺年的问题就可以了! 如何得到某年每个月的第一天是星期几 Private Sub Command1_Click() Dim i As Integer, A As Integer, B As Integer, C As String A = InputBox("请输入年份", "某年每个月的第一天是星期几") Form1.Cls For i = 1 To 12 C = A & "-" & i & "-1" B = Weekday(C) Select Case B Case vbSunday Print A & "年" & i & "月1日是 星期日" Case vbMonday Print A & "年" & i & "月1日是 星期一" Case vbTuesday Print A & "年" & i & "月1日是 星期二" Case vbWednesday Print A & "年" & i & "月1日是 星期三" Case vbThursday Print A & "年" & i & "月1日是 星期四" Case vbFriday Print A & "年" & i & "月1日是 星期五" Case vbSaturday Print A & "年" & i & "月1日是 星期六" End Select Next i End Sub 计算天数及月初月末日期 Function 本月天数(日期 As Date) As Byte 本月天数 = DateSerial(Year(日期), Month(日期) + 1, Day(日期)) - 日期 End Function Function 月末(日期 As Date) As Date 15 access 与 VBA 月末 = DateSerial(Year(日期), Month(日期) + 1, 1) - 1 End Function Function 月初(日期 As Date) As Date 月初 = 日期 - Day(日期) + 1 End Function 本月最后一日是周几 Select Weekday(DateAdd("m",1,DateSerial(Year(Date()),Month(Date()),1)-1)) AS 本月最后一日是周几, 下月最后一日是周几 Select Weekday(DateAdd("m",2,DateSerial(Year(Date()),Month(Date()),1)-1)) AS 下月最后一日是周几, 本月最后一个周5到月底的天数 Select (Weekday(DateAdd("m",1,DateSerial(Year(Date()),Month(Date()),1)-1))+1) Mod 7 AS 本月最后一个周5到月底的天数; 下月最后一个周5到月底的天数 Select (Weekday(DateAdd("m",2,DateSerial(Year(Date()),Month(Date()),1)-1))+1) Mod 7 AS 下月最后一个周5到月底的天数; 本月最后一个周5的日期 Select DateAdd("m",1,DateSerial(Year(Date()),Month(Date()),1))-1-(Weekday(DateAdd("m",1,DateSerial(Year(Date()),Month(Date()),1)-1))+1) Mod 7 AS 本月最后一个周5的日期; 下月最后一个周5的日期 Select DateAdd("m",2,DateSerial(Year(Date()),Month(Date()),1))-1-(Weekday(DateAdd("m",2,DateSerial(Year(Date()),Month(Date()),1)-1))+1) Mod 7 AS 下月最后一个周5的日期;