卡西达 发表于 2012-3-27 17:35:20

access确定某日在当月是第几个星期几的代码

Private Function GetWeekDayStr(SolarDate As Date, m As Byte, n As Byte, w As Byte) As String
'根据日期查询是当月的第几周的周几
Dim tempDate As Date, tempW As Integer
tempDate = DateSerial(Year(SolarDate), Month(SolarDate), 1)
tempW = Weekday(tempDate)
m = Format(SolarDate, "mm")
n = Format(SolarDate, "WW") - Format(tempDate, "WW") + 1
w = Weekday(SolarDate)
If tempW > w Then n = n - 1

End Function
Sub test()
Dim d As Date, m As Byte, n As Byte, w As Byte
d = #1/18/2009#
Call GetWeekDayStr(d, m, n, w)
Debug.Print d & "是" & m & "月的第" & n & "个" & WeekdayName(w)
End Sub

页: [1]
查看完整版本: access确定某日在当月是第几个星期几的代码