473,224 Members | 1,617 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,224 software developers and data experts.

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 11929
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?
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.