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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 YYWW format to YYYY-MM-DD format

Author  Topic 

Suresh1616
Starting Member

2 Posts

Posted - 2010-01-04 : 11:45:07
Can anyone get the date format from yyww format i.e, from yyww to yyyymmdd and the date i expect to be the last day of the week specified i.e, a saturday.

For eg : yyww : 1002 (2010 2nd week)
expected result yyyy-mm-dd : 2010-01-09


Suresh

jackv
Master Smack Fu Yak Hacker

2179 Posts

Posted - 2010-01-04 : 13:33:31
Could you clarify - you have 1002 (i.e 2010 and second week ) - is it the start of the 2nd week you are looking for? as the second week , can be made up of 7 days

Jack Vamvas
--------------------
http://www.ITjobfeed.com
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-01-04 : 15:30:01
See http://weblogs.sqlteam.com/peterl/archive/2009/12/01/How-to-get-a-date-from-Year-week-and-weekday.aspx
or just try

declare @value int = 1002

SELECT DATEADD(YEAR, 2000 + @value / 100, 7 * (@value % 100))



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-05 : 01:54:01
quote:
Originally posted by Peso

See http://weblogs.sqlteam.com/peterl/archive/2009/12/01/How-to-get-a-date-from-Year-week-and-weekday.aspx
or just try

declare @value int = 1002

SELECT DATEADD(YEAR, 2000 + @value / 100, 7 * (@value % 100))



N 56°04'39.26"
E 12°55'05.63"



Did you mean this?

declare @value int = 1002

SELECT DATEADD(YEAR, 2000 + @value / 100-1900, 7 * (@value % 100))


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-05 : 02:10:28
quote:
Originally posted by Suresh1616

Can anyone get the date format from yyww format i.e, from yyww to yyyymmdd and the date i expect to be the last day of the week specified i.e, a saturday.

For eg : yyww : 1002 (2010 2nd week)
expected result yyyy-mm-dd : 2010-01-09


Suresh


You may need this


declare @value int
set @value= 1002

select dateadd(week,datediff(week,0,dateadd(year, 2000 + @value / 100-1900,0))+(@value % 100),-2)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -