We help IT Professionals succeed at work.

How to get the number of week by program

Medium Priority
Last Modified: 2012-03-28
Dear all experts,

I'm looking for a function which is used to get the number of week for specific date, for example.

If I enter 14 Mar 2012 in this function, it will return week 3
If I enter  6 Apr 2012 in this function, it will return week 2

This script will be deployed to an Access or Excel application.  Please kindly advise, thanks.
Watch Question

Martin LissSocial distance - Don't touch your face - Wash your hands for 20 seconds
Most Valuable Expert 2017
Distinguished Expert 2018

The following page explaining week numbers in Excel VBA might prove helpful: Week Numbers In Excel

Otherwise, you could use parsing using the Day() and Weekday() functions, counting how many days from day 1 of the month to the entered day match the "start of a week".
Week numbers are a complicated matter - but only because there are so many different ways to calculate the beginning of the first week.

For a previous question I found the following site: http://www.cpearson.com/excel/WeekNumbers.aspx

If the most standard week numbers is what you require you should use the solution from that question.

That is implementing the following function:
Public Function IsoWeekNumber(InDate As Date) As Long
    IsoWeekNumber = DatePart("ww", InDate, vbMonday, vbFirstFourDays)
End Function

And using it in your code as follows:

Where aDate is a of course a Date type.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.