Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Deathnote
Starting Member
4 Posts |
Posted - 2012-05-27 : 22:54:30
|
I hope someone who has a big heart as big as his brains would take a little out of his time to answer a noobs question.I need to get week of the month by having week in a year as an inputexample201101 = JanW1(First week of january)The formula to get 201101 format is thisDATEPART(YEAR, Molding_Date) * 100 + DATEPART(WEEK, Molding_Date)Molding_Date Format= mm/dd/yyyyPlease reply if the question is confusing |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-27 : 23:51:10
|
[code]declare @year_wk intselect @year_wk = 201122select Month01, WeekOfMonth = @year_wk - (datepart(year, Month01) * 100 + datepart(week, dateadd(month, datediff(month, 0, Month01), 0))) + 1from( select Month01 = dateadd(week, @year_wk % 100 - 1, dateadd(year, @year_wk / 100 - 1900, 0))) d[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
Deathnote
Starting Member
4 Posts |
Posted - 2012-05-28 : 01:07:09
|
You are my god...Thank You khtan your the best :) |
 |
|
Deathnote
Starting Member
4 Posts |
Posted - 2012-05-29 : 01:52:06
|
Im sorry but i have further questions with the given codeyou see201218 = 5th week of april201219 = 2nd week of MayIsnt 201219 suppose to be equal to 1st week of may? |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2012-05-29 : 02:13:59
|
It depends. 1. What is a week for you?2. When is first week of year? N 56°04'39.26"E 12°55'05.63" |
 |
|
|
|
|
|
|