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
 SQL Server 2012 Forums
 Transact-SQL (2012)
 DateandTime functions

Author  Topic 

ozandalkiran
Starting Member

13 Posts

Posted - 2013-01-10 : 03:35:56
SaleBegin
2007-10-30 16:57:54.000
how can i get only year and mounth?
please help me.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-10 : 03:39:06
YEAR(datefield),MONTH(datefield) if you want them in separate column

if you want them combined use

DATENAME(yy,date) + RIGHT('00' + CAST(MONTH(datefield) AS varchar(2)),2)

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

Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-01-10 : 04:16:51
In MSSQL 2012, You can use FORMAT() function to get YYYYMM

SELECT FORMAT(GETDATE(), 'yyyyMM') AS [YYYYMM]

--
Chandu
Go to Top of Page

ozandalkiran
Starting Member

13 Posts

Posted - 2013-01-10 : 04:38:26
thank you
quote:
Originally posted by visakh16

YEAR(datefield),MONTH(datefield) if you want them in separate column

if you want them combined use

DATENAME(yy,date) + RIGHT('00' + CAST(MONTH(datefield) AS varchar(2)),2)

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



Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-01-10 : 04:46:14
wlcm

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

Go to Top of Page
   

- Advertisement -