用什么函数能把星期六和星期天都找到
或者一种什么判断方法也行
Option Explicit
Private Sub Command1_Click()
Dim strStartDay As String
Dim strToday As String
Dim intP As Integer
Dim intWeekDay As Integer
strStartDay = "2012-01-01"
For intP = 0 To 364
strToday = DateAdd("d", intP, strStartDay)
intWeekDay = Weekday(strToday)
If intWeekDay = 7 Then
List1.AddItem strToday & ";周六"
ElseIf intWeekDay = 1 Then
List1.AddItem strToday & ";周日"
End If
Next intP
End Sub
星期六和星期天是循环的,星期到星期天都是间隔5天.
每年365/366天,合52星期,星期六的天数不会超过54次.
找到第一个星期六(从开始日期开始,不会超过7天),接下来没隔5天输出一个星期6,一个星期天.
VB code
Dim StartDay As String
Dim dateStartDay As Date, dateEndDay As Date
Dim i As Date
StartDay = "2012-1-1"
dateStartDay = CDate(StartDay)
dateEndDay = CDate(Year(StartDay) + 1 & "-" & Month(StartDay) & "-" & Day(StartDay)) - 1
For i = 0 To 7
If Weekday(dateStartDay + i) = 7 Then Exit For
Next i
dateStartDay = dateStartDay + i
For i = dateStartDay To dateEndDay
Debug.Print i, Weekday(i)
i = i + 1
Debug.Print i, Weekday(i)
i = i + 5
Next i