15,879,062 members
0.00/5 (No votes)
See more:
Hi
I have to know how to get week number in a given month and year

I have a inputs as Month,Year

Second is i need to get week starting date for that particular week number

It will be very helpful if you could help me on this
Posted
Comments
[no name] 1-Jul-14 7:40am
http://www.google.com/search?q=sql+get+week+number
sushma_bhardwaj 1-Jul-14 7:47am
Hithe url shows current date weeknumber. but I have input as month number ,week number for tht month and year. i don have paerticular date.
[no name] 1-Jul-14 13:45pm
And so? I don't see how that could possibly be a problem when you have not made any effort at all to solve your own problem.
Kornfeld Eliyahu Peter 1-Jul-14 7:40am
In a month there are more than one weeks!?
OriginalGriff 1-Jul-14 7:47am
Oh gawd yes...week number is a PITA: week one is the first week that contains a Thursday in the new year. So the 1st of January can be in week one, or in the last week of the previous year. Which could be Week 51, 52, or 53, depending on when Jan 1st of *that* year fell...
And don't forget that there may be a Feb 29th stuck in the middle which means it isn't as simple as it could be :laugh:

Fortunately, it's all worked out for you these days!

Solution 1

Your question is not clear, whatever it is, you should be able to work out your solution by referring to these:
1. how-to-get-week-number-of-the-month-from-the-date-in-sql-server[^]
2. get-the-week-start-date-and-week-end-date-from-week-number-in-sql[^]

v2
Comments
sushma_bhardwaj 1-Jul-14 7:54am
Hi
thanks for the urls. can we get week number by using month number and year???
example. i have month number as 6 (june) year (2014) for june week number is 23 that means first week number. can we do that .. help me please,

Solution 2

Try this

Select DatePart(week, '2012/11/30') // **returns 48**

Comments
sushma_bhardwaj 1-Jul-14 7:55am
HiI tried this. this is shows correct . but instead of giving date (2014/11/30), is there any logic to get week number from month number and year.
sasidharraju 1-Jul-14 8:08am
just u check this url may be it's useful
http://www.lifeaftercoffee.com/2006/02/01/sql-find-the-week-number-in-a-month/
sasidharraju 1-Jul-14 8:10am
check one more url

http://scn.sap.com/thread/1951103
sushma_bhardwaj 1-Jul-14 8:26am
Thank you
but the TRUNC key word is not supporting inmy DB SQL 2008 :(

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Top Experts
Last 24hrsThis month
 Pete O'Hanlon 160 Graeme_Grant 120 Ravi Bhavnani 90 Dave Kreskowiak 60 Andre Oosthuizen 60
 Pete O'Hanlon 1,695 OriginalGriff 1,270 Graeme_Grant 810 Richard Deeming 743 Dave Kreskowiak 599

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900