Hi Guys,

in vb we can get the week number counting from January. ex Jan 1st is Week 1 and Feb 1st is Week 5 etc by

DatePart(DateInterval.WeekOfYear, Now)

I need to count the week number from a given date. ex: if set the base to July 1st then July 1st is the week 1 and based on that what would be the week number for Oct 3rd? How can I do this in VB?

Kind of simplistic, but you can try something like this;

Private Function WeekOfYear(ByVal dt As Date) As Integer
    Try
        Return dt.DayOfYear / 7
    Catch ex As Exception
        MsgBox("There was a problem retreiving the week of the year!" & vbCrLf & ex.Message)
        Return Nothing
    End Try
End Function

See if this works for your needs:

Private Function WeeksNumFromBasis(ByVal basis As DateTime, ByVal SubjectDate As DateTime) As Double
   Return SubjectDate.Subtract(basis).TotalDays / 7
End Function

Thank you all for your replies and sorry for late to reply. I was able to find excel

formula that suit my need when searching. Now I need to convert that into vb code

please help me on this.

INT((A2-DATE(YEAR(A2+92)-1,10,1)-WEEKDAY(A2))/7)+2

A2 is a any given date.