Please start any new threads on our new site at 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!
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  

Yak Posting Veteran

82 Posts

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

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

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!

Very Important crosS Applying yaK Herder

52326 Posts

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

SQL Server MVP
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
Go to Top of Page

Patron Saint of Lost Yaks

30421 Posts

Posted - 07/10/2013 :  11:02:38  Show Profile  Visit SwePeso's Homepage  Reply with Quote
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 0.02 seconds. Powered By: Snitz Forums 2000