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?

5 Years
Discussion Span
Last Post by ranga.seeman

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

Private Function WeekOfYear(ByVal dt As Date) As Integer
        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

Edited by Begginnerdev


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.


A2 is a any given date.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.