SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Getting Month From Week Number
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Deathnote
Starting Member

Philippines
4 Posts

Posted - 05/27/2012 :  22:54:30  Show Profile  Reply with Quote
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 input

example

201101 = JanW1(First week of january)

The formula to get 201101 format is this
DATEPART(YEAR, Molding_Date) * 100 + DATEPART(WEEK, Molding_Date)
Molding_Date Format= mm/dd/yyyy

Please reply if the question is confusing

khtan
In (Som, Ni, Yak)

Singapore
16746 Posts

Posted - 05/27/2012 :  23:51:10  Show Profile  Reply with Quote
declare	@year_wk	int

select	@year_wk	= 201122

select	Month01, 
	WeekOfMonth	= @year_wk - (datepart(year, Month01) * 100 + datepart(week, dateadd(month, datediff(month, 0, Month01), 0))) + 1
from
(
	select	Month01	= dateadd(week, @year_wk % 100 - 1, dateadd(year, @year_wk / 100 - 1900, 0))
) d



KH
Time is always against us

Go to Top of Page

Deathnote
Starting Member

Philippines
4 Posts

Posted - 05/28/2012 :  01:07:09  Show Profile  Reply with Quote
You are my god...Thank You khtan your the best :)
Go to Top of Page

Deathnote
Starting Member

Philippines
4 Posts

Posted - 05/29/2012 :  01:52:06  Show Profile  Reply with Quote
Im sorry but i have further questions with the given code

you see

201218 = 5th week of april
201219 = 2nd week of May

Isnt 201219 suppose to be equal to 1st week of may?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
29138 Posts

Posted - 05/29/2012 :  02:13:59  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000