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
 Convert year-Week column to year-month-Day

Author  Topic 

nerd12
Starting Member

3 Posts

Posted - 2013-02-09 : 11:43:13
Hi,

I have a column called "date_time" in SQL 2005. this column is of format yyyyww. where ww= number of week in a year. So the format looks like '201243' or 201213 etc

I want to convert this column to YYYYMMDD format. In other words, '20120122' ..'20130101' etc.

Can someone please help me understand how can this column date_time be converted from yyyyww to yyyymmdd

Thank you!!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-09 : 12:22:33
[code]
SELECT DATEADD(wk,(date_time%100)-1,DATEADD(yy,(date_time/100)-1900,0)) AS Date_YMD
FROM table
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

nerd12
Starting Member

3 Posts

Posted - 2013-02-09 : 14:12:55
THANK YOU Visakh!! That worked
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-11 : 00:50:18
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -