count how many weeks in a year?

# Thread: count how many weeks in a year?

1. Member
Join Date
Dec 1969
Posts
42

## count how many weeks in a year?

how can i get how many weeks in any year? and is there any function that i could for example enter number of a week then it will return the start day and end day of this week?<BR>

2. Senior Member
Join Date
Dec 1969
Posts
96,118

## 53, of course

52 weeks plus 1 or 2 days.<BR><BR>Hmmm...can that ever end up being 54 weeks?<BR><BR>Depends on what you mean by "week".<BR><BR>If Jan 1 is on Saturday and it&#039;s a leap year, then Dec 31 will be on Sunday, and you could say that there are 52 full weeks plus two weeks each with only one day in them.<BR><BR>Yes, the DATEADD and DATEDIFF functions can work with weeks. And you can specify both the first day of the week *and* how to determine the first week of the year.<BR><BR>http://msdn.microsoft.com/library/en-us/script56/html/vsfctdatediff.asp<BR><BR>So to find the week number of any given date, something like this:<BR><BR> weekNumber = DateDiff( "ww", #1/1/2004#, Date() )<BR><BR>But as the docs say, you can also manipulate what day is considered first day of week *and* how the first week of the year is determined.<BR><BR>DATEADD allows you to go in the opposite direction. Check it out.<BR><BR>

3. Member
Join Date
Dec 1969
Posts
42

## RE: ok thanks bill but just more comment

hey,<BR>Thanks bill but i still dont know,how can i get the start day of specifice week? i would like to have function that return the start day of a week number?

4. Senior Member
Join Date
Dec 1969
Location
Los Angeles, CA
Posts
21,192

## See what Weekday can do for you <eop>

.

5. Senior Member
Join Date
Dec 1969
Posts
96,118

...on Sunday, then you can get the Sunday at the start of the week and the Saturday at the end of the week this way:<BR><BR>&#060;%<BR>anyDate = ...any date at all...<BR><BR>sundayOfThatWeek = anyDate - Weekday(anyDate) + 1<BR>saturdayOfThatWeek = sundayOfThatWeek + 6<BR>%&#062;<BR><BR>

6. Member
Join Date
Dec 1969
Posts
42

## RE: Well im sorry but im still kind of lost here.

Well can you some one give me function work like this.<BR><BR>Response.Write StartOfWeek(24,2003)<BR>i want it to right the first day of week 24 in year 2003.<BR>Do anybody knows how?

7. Senior Member
Join Date
Dec 1969
Posts
96,118

## You *still* have to tell us...

...what you are defining as the first week of the year.<BR><BR>But assuming you are willing to live with the defaults that VBScript uses:<BR><BR>&#060;%<BR>Function StartOfWeek( weeknum, yr )<BR> Dim dt<BR> &#039; as I said, look at DateAdd...<BR> &#039; just add specified number of weeks to Jan 1 of given year<BR> &#039; (we assume that weeknumber 1 means first week of year, so we<BR> &#039; need to add ZERO weeks, etc.)<BR> dt = DateAdd( "ww", weeknum-1, DateSerial( yr, 1, 1 ) )<BR> &#039; and then I *explicitly* showed you how to do the next step:<BR> StartOfWeek = dt - Weekday(dt) + 1<BR>End Function<BR>%&#062;<BR><BR>Watch out!<BR> Response.Write( 53, 2003 )<BR>and<BR> Response.Write( 1, 2004 )<BR>will both give you the same answer! (28 Dec 2003, which is correct)<BR><BR><BR>

8. Member
Join Date
Dec 1969
Posts
42

## Re: Ok thanks bill i will try this.

thanks alot Bill, the start of the week is (Monday) so i guess i dont have to change anything right?

9. Senior Member
Join Date
Dec 1969
Posts
96,118

## Start of week is *SUNDAY*...

...by VBScript default!<BR><BR>The days are numbered from vbSunday=1 to vbSaturday=7.<BR><BR>Read the docs.<BR><BR>If your week goes from Monday=1 to Sunday=7 then you will have to adjust things.<BR><BR>In particular, you&#039;ll have to pass an extra argument to the Weekday function.<BR><BR>Something like:<BR> dt - Weekday( dt, vbMonday ) + 1<BR><BR>Once again READ THE DOCS. There is NO SUBSTITUTE for reading the documentation. None. <BR>http://msdn.microsoft.com/library/en-us/script56/html/vsfctWeekday.asp

10. Member
Join Date
Dec 1969
Posts
42

## RE: Start of week is *SUNDAY*...

ok thanks Bill i really appreciate this. thanks

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•