Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Get date from week number in a year
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

allan8964
Posting Yak Master

249 Posts

Posted - 02/11/2014 :  16:10:03  Show Profile  Reply with Quote
Hi there,

Can I get a date from a week number in a certain year, like I know it's week 7 in 2014 (I may know the month.)?
Thanks in advance.

TG
Flowing Fount of Yak Knowledge

USA
6065 Posts

Posted - 02/11/2014 :  20:05:11  Show Profile  Reply with Quote
maybe this?

select dateadd(week, 7, '2014-01-01')

Be One with the Optimizer
TG
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/11/2014 :  23:28:44  Show Profile  Reply with Quote
is it week of year value you get or week for month? can you give an example?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 02/12/2014 :  10:05:26  Show Profile  Reply with Quote
First of all thanks for replies.
The week number here I have is week in a year. I have values of year like 2014, the month like Feb, June, etc. From these 3 I need to know the date range starting from Sun to Sat. For example, we're in week 7 now and Feb. 9 - Feb. 15 is the date range I am looking for.
For TG's statement I noticed it gave the one more than it's expected. That's because 2014-01-01 is in week one so if we use dateadd() function then should subtract 1, like select dataadd(week, 6, '2014'). But this one only gives one date based 01-01, 2014-01-01 is on Wend so the statement gives the date of Wedn too.
Thanks again.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 02/12/2014 :  17:32:57  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Like this one?
http://weblogs.sqlteam.com/peterl/archive/2009/12/01/How-to-get-a-date-from-Year-week-and-weekday.aspx



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/13/2014 :  07:49:57  Show Profile  Reply with Quote
do you mean this?

--SELECT * FROM RVNUTYP_EXCPTN


DECLARE @Year int,@WeekNo int= 7
SET @Year=2014

SELECT DATEADD(dd,DATEDIFF(dd,0,DATEADD(wk,@WeekNo-1,DATEADD(yy,@Year-1900,0)))/7 * 7-1,0),
DATEADD(dd,DATEDIFF(dd,0,DATEADD(wk,@WeekNo-1,DATEADD(yy,@Year-1900,0)))/7 * 7+5,0)



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

allan8964
Posting Yak Master

249 Posts

Posted - 02/22/2014 :  16:54:57  Show Profile  Reply with Quote
Gentlemen, sorry for not following up. But these are all what I need. Thank you SO much!!!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 02/23/2014 :  02:51:46  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next 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.04 seconds. Powered By: Snitz Forums 2000