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
 How to concatenate YYYYMM from "2013-11-22 14:40:0

Author  Topic 

Chinni
Yak Posting Veteran

95 Posts

Posted - 2013-05-30 : 16:44:09
Hello,

Need help display 201311 (YYYYMM) from "2013-11-22 15:40:00.000" format

Thank you

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2013-05-30 : 16:51:13
assuming the value one of sql server's date type datatypes:

select convert(varchar(6), getdate(), 112)

OUTPUT:
201305

Be One with the Optimizer
TG
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-05-30 : 17:54:32
Here is another way:
SELECT FORMAT(SYSDATETIME(), 'yyyyMM', 'en-us')
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2013-05-30 : 17:58:17
Here is another:
SELECT LEFT(REPLACE('2013-11-22 15:40:00.000', '-', ''), 6)
Go to Top of Page
   

- Advertisement -