Week number in a Month
| This is sample code. Add error handling and adjust to your requirements as necessary. |
-- There's simpler and shorter version in the comments below DECLARE @dt DATETIME, @WeekOfMonth TINYINT SET @dt = '2007-07-08' SET @WeekOfMonth = (DAY(@dt) + (DATEPART(dw, DATEADD (MONTH, DATEDIFF (MONTH, 0, @dt), 0)) --^-- The day of the week for the first day of month -1) -- # of days to add to make the first week full 7 days -1)/7 + 1 PRINT @WeekOfMonth
Another way
Try this
Shorter and simpler
It's shorter and simpler.
Thanks.
Very Cool. Thanks for posting
Very Cool.
Thanks for posting this...
Re: Very Cool. Thanks for posting
Really Helpful. Thank You
Re: Another way
Great.... Just the thing I was looking for.
Thanks...
wow..cool......thanx lot...
wow..cool......thanx lot...
One use for this week of the month:
The results (if ran with default parameters):
Agreed Very Cool!
Agreed Very Cool!
will it works for the date
will it work for the date 1/31/2010 ?
if so it will be the 6th week for that month.
Yes it's correct
Yes it's correct. The 1/31/2010 is Sunday of the 6th week in the month.
Thanks for the quick
Thanks for the quick response.
Then it wont work for me, i need it as a 6th week, So please can you give me a query to make it as 5th week like
jan 1st ---7th 1st week
jan 8th -- 14th 2nd week
jan 15th--21nd 3rd week
jan 22rd--28th 4th week
jan 29th -- what ever comes hear as 5th week
and so on.
I mean jan 1st of 2010 to be as first day to calculate the week number.
It's simple
It's simple
Thank you very very much
Thank you very very much sergey
Sergey! perfect solution!
Sergey! perfect solution! I've been looking for this information for 2 days! Thanks again.
Calculate first and last day of a week in a month
Hi Sergey ,
I want to calculate first day and last day of a week in a month.For Example,
sep 01 2011 - sep 03 2011,
sep 04 2011 - sep 10 2011,
sep 11 2011 - sep 17 2011 ,
sep 18 2011 - sep 24 2011,
sep 25 2011 - sep 30 2011,