Previous month | SQL Server Performance Forums

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=’:)‘ /><br /><br />SELECT dateadd(month, -1, ‘20070117’)<br /><br />MohammedU.<br />Moderator<br />SQL-Server-Performance.com
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=’:)‘ /><br /><br />SELECT dateadd(month, -1, ‘20070117’)<br /><br />MohammedU.<br />Moderator<br />SQL-Server-Performance.com<br /><hr height="1" noshade id="quote"></font id="quote"></blockquote id="quote"><br />thanks [<img src=’/community/emoticons/emotion-1.gif’ alt=’:)‘ />]<br /><br /><hr noshade size="1"><br /><font color="blue"><font size="1"><i>KH</i></font id="size1"></font id="blue">
Thank you so much.
Mattie
]]>