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 Ray via SQLMonster.com on 07/20/05 21:08

Hi Stu,

Thank you very very much ..... it was a great help.

Best regards,

Stu wrote:
>If you don't have a calendar table (which can be very helpful for
>situations like this), you can do it on-the-fly using SQL Server like
>so:
>
>SELECT DATEADD(m, -1, FirstOfCurrentMonth) as FirstOfPreviousMonth,
> DATEADD(d, -1, FirstOfCurrentMonth) as LastOfPreviousMonth
>FROM (SELECT CONVERT(smalldatetime,DATENAME(m, GetDate())
> + ' 1,' + DATENAME(yyyy, GETDATE())) as FirstOfCurrentMonth) a
>
>Of course, you'll want to do the formatting on the client side.
>
>HTH,
>Stu


--
Message posted via SQLMonster.com
http://www.sqlmonster.com/Uwe/Forums.aspx/sql-server-general/200507/1

 

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

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