View Single Post

   
  #6 (permalink)  
Old 02-29-2008, 08:29 AM
Ray via SQLMonster.com
 
Posts: n/a
Default Re: Code for 1st day & the Last day of the Previous Month


Ross,

Thank you so much ....

Ross Presser wrote:
>> Hi there,
>>

>[quoted text clipped - 8 lines]
>>
>> Regards,

>
>declare @d1 smalldatetime
>declare @d2 smalldatetime
>declare @d3 smalldatetime
>
>-- @d1 is the input date
>set @d1 = CURRENT_TIMESTAMP
>-- truncate hours, min, etc.
>set @d1 = convert(smalldatetime, floor(convert(float, @d1)))
>
>-- @d2 - last day of previous month
>
>set @d2 = dateadd(day, - datepart(day, @d1), @d1)
>
>-- @d3 - first day of previous month
>
>set @d3 = dateadd(day, - datepart(day, @d2) + 1, @d2)



--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums...neral/200507/1
Reply With Quote