Get WeekNumber for a given date
This snippet will allow you to pass a string as a date, and get the week number for that calendar year, returned as an integer
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
Public Function WeekNum(sDate As String) As Integer
Dim iYear As Integer
Dim iMon As Integer
Dim sTemp As String
Dim iDay11 As Integer
Dim iDiff As Integer
If IsDate(sDate) And sDate <> "12:00:00 PM" Then
'determine the year
iYear = Year(sDate)
'determine the month
iMon = Month(sDate)
'determine weekday of Jan 1st
sTemp = "1/1/" & Trim(Str$(iYear))
iDay11 = Weekday(sTemp)
'now calculate the difference in days
iDiff = DateDiff("d", sTemp, sDate)
'base week
WeekNum = Int(iDiff / 7) + 1
'check for rollover based on day of week
If Weekday(sDate) < iDay11 Then
WeekNum = WeekNum + 1
End If
End If
End Function
Original Comments (3)
Recovered from Wayback Machine