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
 General SQL Server Forums
 New to SQL Server Programming
 Previous Month
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

wsilage
Yak Posting Veteran

USA
82 Posts

Posted - 07/10/2013 :  08:56:41  Show Profile  Reply with Quote
Hi,

I can get the name of the month by doing this...

SELECT
Datename(month,getdate()) as monthName

But I am not able to get the previous Month? How can I do that I thought by putting -1 it would do that for me, but it doesn't.

What other suggestions can you give me? Thanks!

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

Posted - 07/10/2013 :  08:59:31  Show Profile  Reply with Quote
SELECT
Datename(month,DATEADD(mm,DATEDIFF(mm,0,getdate())-1,0)) as monthName

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

James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 07/10/2013 :  09:02:29  Show Profile  Reply with Quote
If you are on SQL 2012
datename(month,eomonth(getdate(),-1))
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

Sweden
30421 Posts

Posted - 07/10/2013 :  11:02:38  Show Profile  Visit SwePeso's Homepage  Reply with Quote
SELECT
Datename(month,dateadd(month, -1, getdate())) as monthName


N 56°04'39.26"
E 12°55'05.63"
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 1.58 seconds. Powered By: Snitz Forums 2000