473,466 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Week Number

Hi,

I am trying to figure out a way to get the week number of the current week.
I know this is relatively easy using the calendar year (starting from
January to now). However, I want to do it so I start in October on the first
monday of the month, so today's date would be the 10th week.

Any ideas?

Shahid
Jul 22 '05 #1
4 11964
Shahid Juma wrote:
Hi,

I am trying to figure out a way to get the week number of the current
week. I know this is relatively easy using the calendar year
(starting from January to now). However, I want to do it so I start
in October on the first monday of the month, so today's date would be
the 10th week.

Any ideas?

Shahid

Create a calendar table that maps each date to the week number you wish to
assign to it.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Jul 22 '05 #2
Shahid Juma wrote on 09 dec 2004 in
microsoft.public.inetserver.asp.general:
I am trying to figure out a way to get the week number of the current
week. I know this is relatively easy using the calendar year (starting
from January to now). However, I want to do it so I start in October
on the first monday of the month, so today's date would be the 10th
week.


r = datediff("w","2004-05-04","2004-12-15")+1

or perhaps

r = datediff("ww","2004-05-04","2004-12-15")+1

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 22 '05 #3
Shahid Juma wrote:
I am trying to figure out a way to get the week number of the current
week. I know this is relatively easy using the calendar year
(starting from January to now). However, I want to do it so I start
in October on the first monday of the month, so today's date would be
the 10th week.


This is especially difficult when deciding what to do when dealing with
early (pre-Monday) October dates. Take October 1, 2004, for example. Since
your calendar starts on October 4 (the first Monday), you have to move the
start date back to October 6, 2003. Here is a functional JScript
implementation:

Date.prototype.getDoW = function() {
var D1 = new Date(
this.getFullYear(),this.getMonth(),this.getDate()
), D2 = new Date(2000,0,1)
return (
Math.round((D1.valueOf() - D2.valueOf())/86400000)%7 + 6
)%7
}
function weekNum(d) {
var i=0, Day1 = new Date(d.getFullYear(),9)
while (Day1.getDoW() != 1) {
if (Day1 > d) Day1 = new Date(d.getFullYear()-1,9)
Day1.setDate(++i)
}
return Math.ceil((d.valueOf() - Day1.valueOf())/604800000)
}
Response.Write(weekNum(new Date()))
NOTE that Date.getDoW() is merely a zero-based implementation of VBScript's
Weekday Function. Consequently, a VBScript implementation would look
something like this:

Function WeekNumber(D)
Dim Day1
Day1 = DateSerial(Year(D),10,1)
While Weekday(Day1) <> 2
If Day1 > D Then Day1 = DateSerial(Year(D)-1,10,1)
Day1 = DateAdd("d",1,Day1)
Wend
WeekNumber = DateDiff("w",Day1,D) + 1
End Function

Response.Write(WeekNumber(Now))

As you can see, this implementation benefits from VBScript's superior
date-handling functions. It is a straigtforward read, while the JScript
version is not.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Jul 22 '05 #4
Thank you all for your help! I got it working!

Shahid

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:eG**************@tk2msftngp13.phx.gbl...
Shahid Juma wrote:
I am trying to figure out a way to get the week number of the current
week. I know this is relatively easy using the calendar year
(starting from January to now). However, I want to do it so I start
in October on the first monday of the month, so today's date would be
the 10th week.
This is especially difficult when deciding what to do when dealing with
early (pre-Monday) October dates. Take October 1, 2004, for example. Since
your calendar starts on October 4 (the first Monday), you have to move the
start date back to October 6, 2003. Here is a functional JScript
implementation:

Date.prototype.getDoW = function() {
var D1 = new Date(
this.getFullYear(),this.getMonth(),this.getDate()
), D2 = new Date(2000,0,1)
return (
Math.round((D1.valueOf() - D2.valueOf())/86400000)%7 + 6
)%7
}
function weekNum(d) {
var i=0, Day1 = new Date(d.getFullYear(),9)
while (Day1.getDoW() != 1) {
if (Day1 > d) Day1 = new Date(d.getFullYear()-1,9)
Day1.setDate(++i)
}
return Math.ceil((d.valueOf() - Day1.valueOf())/604800000)
}
Response.Write(weekNum(new Date()))
NOTE that Date.getDoW() is merely a zero-based implementation of

VBScript's Weekday Function. Consequently, a VBScript implementation would look
something like this:

Function WeekNumber(D)
Dim Day1
Day1 = DateSerial(Year(D),10,1)
While Weekday(Day1) <> 2
If Day1 > D Then Day1 = DateSerial(Year(D)-1,10,1)
Day1 = DateAdd("d",1,Day1)
Wend
WeekNumber = DateDiff("w",Day1,D) + 1
End Function

Response.Write(WeekNumber(Now))

As you can see, this implementation benefits from VBScript's superior
date-handling functions. It is a straigtforward read, while the JScript
version is not.
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use of this email address implies consent to these terms. Please do not contact me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

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...
5
by: Bullschmidt | last post by:
If I know the week number and the year, how can I calc the beginning and ending dates of the week? For background I'm going to do some grouping by week but don't just want to call the weeks Week...
7
by: Shuffs | last post by:
Could someone, anyone please tell me what I need to amend, to get this function to take Sunday as the first day of the week? I amended the Weekday parts to vbSunday (in my code, not the code...
5
by: Peter Bailey | last post by:
I have a query that returns , and : 12/05/04 3 Wednesday 13/05/04 0 Thursday and so on what I would like to do now is count the number of bookings by week so from monday to...
9
by: Ray | last post by:
I need to convert the normal calendar to show the week no., the period no. and the financial year. The financial year format is as follows:- Date start: 2 May, 2005 7 days a week, 4 weeks a...
2
by: Rustan | last post by:
Hi Im using GregorianCalendar to find out the current years week numbers. When the user chooses a week number in a dropdown i want to show that week in a table with the corresponding dates. For...
3
by: Mal | last post by:
Hello, Any advice on a function to convert a given week number to a date? Ideally I'd like the first day of that week. I'm using this to compare year to year....using the week number as the...
18
by: Jen | last post by:
Is it possible (how) to display a new record every week (or day) from a recordset?
6
by: aarklon | last post by:
Hi folks, I found an algorithm for calculating the day of the week here:- http://www.faqs.org/faqs/calendars/faq/part1/index.html in the section titled 2.5 what day of the week was 2 august...
4
by: Vince | last post by:
Given a week Number, how do I calculate the date that for the Monday of that week?
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,...
1
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.