Is The Date On The Weekend

This function will figure out if the given date lands on a weekend.

    Public Shared Function IsWeekend(ByVal dateOfInterest As DateTime) As Boolean
Dim d, m, y, w As Integer
d = dateOfInterest.Day
m = dateOfInterest.Month
y = dateOfInterest.Year


If m = 1 Or m = 2 Then
m += 12
y -= 1
End If


w = CInt((d + 2 * m + 3 * (m + 1) / 5 + y + y / 4 - y / 100 + y / 400) Mod 7)
If w <> 6 And w <> 7 Then
Return False
Else
Return True
End If
End Function

Another function to do the weekend check could be this:

    Private Const ERR_INVALID_DATE = 20000
Private Const ERR_INVALID_DATE_MSG = "Date Required"

Public Function IsWeekend(ByVal DateValue As Object) As Boolean

Dim dDateValue As Date

If Not IsDate(DateValue) Then
Err.Raise(ERR_INVALID_DATE, ERR_INVALID_DATE_MSG)
Exit Function
End If

dDateValue = CDate(DateValue)
IsWeekend = (Weekday(dDateValue) Mod 6 = 1)

End Function
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s