Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 12890

How can I display previous monthname including the year?

$
0
0

I have the following sql statement:

SELECT Cast(datename(month, dateadd(mm, -1, getdate())) as varchar(15)) + '-' + Cast((DATEPART(YYYY,GETDATE())) As CHAR(4))

The result displays as July-2014 which is correct for previous month...

But on next year January-2015 it will display December-2015.

Is it possible to have the date shown as December-2014?

I appreciate any help.

Thanks in advance.


Viewing all articles
Browse latest Browse all 12890

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>