SQL Server Performance Forum – Threads Archive
Previous month
Hey,I need to find the previous month of a date thats been provided. eg. Jan 7th 2007 (was provided)
Dec 2006 should be the answer. Thank for you help
Mattie
use dateadd(month, -1, ‘200701017’)
KH
Sorry! simple correction..one extra ZERO…<img src=’/community/emoticons/emotion-1.gif’ alt=’

declare @date smalldatetime
set @date = ‘2007/01/17’ SELECT month(dateadd(month, -1, @date))
SELECT year(dateadd(month, -1, @date))
—————————————-
Contributing Editor, Writer & Forums Moderator
http://www.SQL-Server-Performance.Com Visit my Blog at
http://dineshasanka.spaces.live.com/
<blockquote id="quote"><font size="1" face="Verdana, Arial, Helvetica" id="quote">quote:<hr height="1" noshade id="quote"><i>Originally posted by MohammedU</i><br /><br />Sorry! simple correction..one extra ZERO…<img src=’/community/emoticons/emotion-1.gif’ alt=’


Thank you so much.
Mattie
]]>