. . Hong Kong Software Company
software house
Expert in web-based solutions
Software House in Hong Kong

Microsoft Certified Solution Developer

 

Chief Architect's Blog on software development

01 Feb 2008
Week Of Year Helper Functions
Some companies use week of year instead of month for keeping record.  So, what is the first day of Week 15 in 2008?  What is the week of year of 15 Feb 2008?  Here are two helper functions:
Public Function WeekOfYear(ByVal d As Date) As Integer
        Return DateDiff(DateInterval.WeekOfYear, CDate("1 Jan " & d.Year.ToString), d) + 1
End Function
 
Public Function StartDateOfWeekOfYear(ByVal weekOfYear As Integer, ByVal Year As Integer) As Date
        If weekOfYear < 1 OrElse weekOfYear > 53 Then
            Throw New ApplicationException("Invalid Week Of Year")
        End If
        Dim d As Date = CDate("1 Jan " & Year.ToString)
        If weekOfYear = 1 Then
            Return d
        Else
            Return d.AddDays(((weekOfYear - 1) * 7) - d.DayOfWeek)
        End If
 End Function
 
Please feel free to download the code from here.

Member Log in
User ID:
Password:
 
 
Hong Kong Software House



 
March On to the Information Era. Realize your Vision via Customized Software.