You are here: Re: Date Range for SQL 2005 « MsSQL Server « IT news, forums, messages
Re: Date Range for SQL 2005

Posted by Erland Sommarskog on 07/13/07 21:37

Aaron (odysseus183@hotmail.com) writes:
> I was reading the article and was unable to get some of queries to
> execute. Can anyone help get these to work:
>
> How to get the last day of the previous month? And the last day of the
> current month?
>
> SELECT DATEADD(month, DATEDIFF(month, '20000101', CURRENT_TIMESTAMP),
> '19991231')
> SELECT DATEADD(month, DATEDIFF(month, '20000101', CURRENT_TIMESTAMP),
> '20000131')

SELECT dateadd(DAY, -1, convert(char(6), CURRENT_TIMESTAMP, 112) + '01')

SELECT dateadd(DAY, -1,
dateadd(MONTH, 1, convert(char(6), CURRENT_TIMESTAMP, 112) + '01'))


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

 

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

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