dates

1. uc
Member
Join Date
Dec 1969
Posts
63

## dates

Input :any valid date, eg:12-mar-2001<BR>Output required: 3rd week of the month<BR><BR>that is for a given date as an input i require the number of the week in that month.<BR><BR>Pls tell me the possibilites from the combination of sqlserver and ASP or Just ASP or just SQLserver<BR><BR><BR>

2. Senior Member
Join Date
Dec 1969
Posts
503

## RE: dates

i take it you need to get the number of the week in the month? like "the 24th march the third week of this month"?<BR>

3. uc
Member
Join Date
Dec 1969
Posts
63

## RE: dates

Hi too..<BR><BR>yes that is what i want<BR><BR>thanx

4. Senior Member
Join Date
Dec 1969
Posts
1,913

## What do consider a week to be?

do you mean that the 5th will ALWAYS be in week 1 as there are 7 days in a week, or do you mean that (as in March 2001) the 5th would be in week 2 as it was a Monday?

5. Senior Member
Join Date
Dec 1969
Posts
1,913

## Give this a try ...

This works by assuming Sunday to be the 1st day of the week. <BR><BR>It calculates what the date would be for the Sunday of the week in which the chosen month begins (1st March 2001 was a Tuesday so the 1st Sunday was actually the 25th of Feb). <BR><BR>Then it divides the number of days between the 1st sunday and the date you entered to calculate the week number.<BR><BR>Sorry, I don&#039;t know how to do this in Sql Server, only in Asp/VbScript or JavaScript at a push.<BR><BR>&#060;%<BR>MyDate = "12-mar-01"<BR>BaseDate = "01/" & DatePart("m", MyDate) & "/" & DatePart("yyyy", MyDate) &#039; Go to the 1st of the month<BR>BaseDate = DateAdd("d", -(DatePart("w", BaseDate) - 1), BaseDate) &#039; Get Sunday of 1st week<BR>TheDiff = DateDiff("d", BaseDate, MyDate) / 7 &#039; Calculate the number of days between our date and the 1st Sunday<BR>If InStr(1, TheDiff, ".") &#062; 0 Then<BR> TheWeekNum = Left(TheDiff, 1) + 1 &#039; If the result has a decimal point, add 1<BR>Else<BR> TheWeekNum = TheDiff<BR>End If<BR>Response.Write MyDate & " falls in week " & TheWeekNum<BR>%&#062;

6. uc
Member
Join Date
Dec 1969
Posts
63

## RE: What do consider a week to be?

Yes eddie, I mean that (as in March 2001) the 5th would be in week 2 as it was a Monday?

7. uc
Member
Join Date
Dec 1969
Posts
63

## RE: Give this a try ...

Eddie, your soln. doesnt work.<BR><BR>let me rephrase the problem,<BR>for example 12-mar-2001 was third week for the month march (not of the year)<BR>and 12-mar-1999 was second week for the month march

8. Senior Member
Join Date
Dec 1969
Posts
1,913

## Thats exactly what the code does ...

If I set it to 12-mar-01 it returns 3, and for 12-mar-99 it returns 2.<BR><BR>Give it a try.

9. uc
Member
Join Date
Dec 1969
Posts
63

## RE: it gives week 10 for 12-mar-99

eddie,<BR>it gives week 10 for 12-mar-99<BR><BR>

#### Posting Permissions

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