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 2012 Forums
 Transact-SQL (2012)
 convert char to date - week format
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

czajkuss
Starting Member

3 Posts

Posted - 07/25/2013 :  04:10:40  Show Profile  Reply with Quote
Hi, I have column with information about day of seeling goods in format 'YYYYMMDD' and I have to convert it on format YYYY-quater and YYYY-MM-week? Have you got any idea how handle with this case?? Thanks!!

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/25/2013 :  04:41:53  Show Profile  Reply with Quote
whats the base datatype of the field?
if its datetime use

DATENAME(year,datefield) + '-' + DATENAME(quarter,datefield) AS [YYYY-quater]

DATENAME(year,datefield) + '-' + RIGHT('00' + CAST(DATEPART(month,datefield) AS varchar(2)),2) + '-' + DATENAME(week,datefield) AS [YYYY-MM-Week]


otherwise you need to first convert it to date before you apply above logic

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

czajkuss
Starting Member

3 Posts

Posted - 07/25/2013 :  05:04:59  Show Profile  Reply with Quote
It works, thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52309 Posts

Posted - 07/25/2013 :  05:07:52  Show Profile  Reply with Quote
welcome

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

SwePeso
Patron Saint of Lost Yaks

Sweden
30101 Posts

Posted - 07/25/2013 :  06:32:12  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Remember, WEEK is not ISO Week number. If you want ISO Week number, replace Week parameter with ISO_WEEK instead.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
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.05 seconds. Powered By: Snitz Forums 2000