VBA/Excel/Access/Word/Date Functions/Weekday — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 15:48, 26 мая 2010
Содержание
Get the weekend between startDate and endDate
<source lang="vb">
Function TestIfWeekend(startDate, endDate)
Dim varDate TestIfWeekend = "XXX" If startDate = 0 Then Exit Function If endDate = 0 Then Exit Function If endDate - startDate < 2 Then Exit Function For varDate = startDate To endDate - 1 If WeekDay(varDate) = 7 Then TestIfWeekend = "OK": Exit Function End If Next varDate
End Function
</source>
The Weekday function values
<source lang="vb">
Constant Value vbSunday 1 vbMonday 2 vbTuesday 3 vbWednesday 4 vbThursday 5 vbFriday 6 vbSaturday 7
</source>
Use Weekday to get the weekday value from a date
<source lang="vb">
Private Sub myTime1()
Dim time As Date Dim theHour As Integer Dim theDayOfTheWeek As Integer time = Now theHour = Hour(time) theDayOfTheWeek = Weekday(time) If (theHour > 8) And (theHour < 17) Then If (theDayOfTheWeek > 0) And (theDayOfTheWeek < 6) Then MsgBox ("You should be at work!") Else MsgBox ("I love weekends") End If Else MsgBox ("You should not be at work!") End If
End Sub
</source>
Weekday(Date)
<source lang="vb">
Sub Main2()
Debug.Print "Today"s date is: " & Date Debug.Print "The day of the week is: " & Weekday(Date)
End Sub
</source>
Weekday(date) returns A Variant/Integer containing the day of the week represented by date
<source lang="vb">
Sub dateDemo16()
Debug.Print Weekday(#4/1/2006#)
End Sub
</source>