You are here: Re: Code for 1st day & the Last day of the Previous Month « MsSQL Server « IT news, forums, messages
Re: Code for 1st day & the Last day of the Previous Month

Posted by Ross Presser on 07/20/05 20:41

On Wed, 20 Jul 2005 16:56:42 GMT, Ray via SQLMonster.com wrote:

> Hi there,
>
> See if you can help me with the following:
>
> I need to write an SQL code that will return me:
>
> The 1st day & the Last day of the Previous Month in the following format
> (smalldatetime):
>
> yyyy-mm-dd hh:mi:ss (24h)
>
> 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)

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация