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

wsilage
Starting Member

USA
48 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
52249 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

3323 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
29910 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  
 New 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.06 seconds. Powered By: Snitz Forums 2000