|
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]
|