Please start any new threads on our new site at http://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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)
 DateandTime functions
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ozandalkiran
Starting Member

Turkey
13 Posts

Posted - 01/10/2013 :  03:35:56  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/10/2013 :  03:39:06  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2241 Posts

Posted - 01/10/2013 :  04:16:51  Show Profile  Reply with Quote
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

Turkey
13 Posts

Posted - 01/10/2013 :  04:38:26  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/10/2013 :  04:46:14  Show Profile  Reply with Quote
wlcm

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

Go to Top of Page
  Previous Topic Topic Next 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.08 seconds. Powered By: Snitz Forums 2000