473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calculating the Week Number in a given month

30
I would like to know if there is a function available to determine the week number in any given month.

For example March 20th, 2010 would be Week #3
Mar 20 '10 #1

✓ answered by ADezii

To the best of my knowledge, there is no Function that will return the Week of the Month for a given Date. I through together a Custom Function that you can test, but I've had no time to test it myself and I am not sure of its accuracy.
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalcWeekOfMonth(dteDate As Date) As Byte
  2.   fCalcWeekOfMonth = DatePart("ww", dteDate) - _
  3.                     DatePart("ww", DateSerial(Year(dteDate), Month(dteDate), 1)) + 1
  4. End Function
Expand|Select|Wrap|Line Numbers
  1. MsgBox fCalcWeekOfMonth(#3/20/2010#)
returns
Expand|Select|Wrap|Line Numbers
  1. 3

5 17908
ADezii
8,834 Expert 8TB
To the best of my knowledge, there is no Function that will return the Week of the Month for a given Date. I through together a Custom Function that you can test, but I've had no time to test it myself and I am not sure of its accuracy.
Expand|Select|Wrap|Line Numbers
  1. Public Function fCalcWeekOfMonth(dteDate As Date) As Byte
  2.   fCalcWeekOfMonth = DatePart("ww", dteDate) - _
  3.                     DatePart("ww", DateSerial(Year(dteDate), Month(dteDate), 1)) + 1
  4. End Function
Expand|Select|Wrap|Line Numbers
  1. MsgBox fCalcWeekOfMonth(#3/20/2010#)
returns
Expand|Select|Wrap|Line Numbers
  1. 3
Mar 20 '10 #2
NeoPa
32,556 Expert Mod 16PB
I don't believe there is a built-in function available anywhere. You could write your own, but you'd need to be more clear as to what exactly constituted the first week before you started.
Mar 20 '10 #3
missinglinq
3,532 Expert 2GB
The OP's example would indicate, to me, that he wanted it just as it would appear on a printed calendar.

I gave the code a pretty good test run, including Februarys with both 28 and 29 days, and could find no problems with it.

Linq ;0)>
Mar 20 '10 #4
xraive
30
Thank you so much ADezii for your prompt response.
Mar 24 '10 #5
ADezii
8,834 Expert 8TB
You are quite welcome.
Mar 24 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Dave Smithz | last post by:
Help, I am sure this has been asked before but it is difficult to search for. Given a date, is there a function or a already written script out there that will allow my to get the previous...
1
by: cg_news | last post by:
I understand that the GregorianCalendar can be used to calculate the week of year for a date, and after instantiating a GregorianCalendar object with the no arg constructor, I can infact retrieve...
2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
13
by: SimonC | last post by:
I would like to return data from the last 2 weeks of each given month in Javascript, but in 2 formats. So, the penultimate week (Monday to Sunday) and the last week (Monday to ??) I'm not...
2
by: Simon Pleasants | last post by:
I recently built a database to help keep track of shipments we are bringing into the country. Included in the database are a number of fields with dates for shipment, ETA etc. Each one of these...
3
by: Wired Hosting News | last post by:
Lets say I have 10 products in 10 different stores and every week I get a report from each store telling me how many items they have left for each of the 10 products. So each week I enter in 100...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
3
by: sbaird | last post by:
Aloha from Hawaii, I'm beating my head on the wall here. I have a recruiting contact managment database I'm trying to create. Managers (there ar 14 of them) have to make a certain number of...
2
by: tasmontique | last post by:
I am working on an access 2002 flight schedule database. I am new to access but have some basic understanding of sql and vb6 code. I have learned a lot from this website. Thanks much Hopefully...
3
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, is there a way if you are given a Year and a Week an easy way to go back say 26 weeks ago from given year/week. for example, given: 2008/16 26 weeks prior is: 2007/43 thanks,
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.