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
 Date Convertion

Author  Topic 

kishoremcp
Starting Member

41 Posts

Posted - 2013-09-19 : 03:53:37
Hi,

I have a date format in SQL database like 2008-03-13 13:22:38.000

I want the output as 200803(YYYYMM).

Please hlep me how to convert it.

Thanks in advance..

Regards,
Kishore

Regards
Kishore

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-09-19 : 04:28:12
SELECT CONVERT(CHAR(6), Col1, 112) FROM dbo.Table1;


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

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-09-19 : 04:38:49
Refer this link for different date time formats
http://www.sql-server-helper.com/sql-server-2008/sql-server-2008-date-format.aspx


--
Chandu
Go to Top of Page

VeeranjaneyuluAnnapureddy
Posting Yak Master

169 Posts

Posted - 2013-09-19 : 05:19:15
SELECT CONVERT(CHAR(6),CAST(GETDATE() AS DATE),112)

veeranjaneyulu
Go to Top of Page

sigmas
Posting Yak Master

172 Posts

Posted - 2013-09-19 : 05:36:32
SELECT replace(left(cast(getdate() as date),7),'-','')
Go to Top of Page
   

- Advertisement -