|
Posted by Dan Guzman on 07/14/07 14:10
> How to get the last day of the previous month? And the last day of the
> current month?
Below alternative to the technique Erland posted. Although it's not as
clear as building a date string, it performs better in situations where
dates are calculated for each row. The overhead of converting to/from
date/string can add up for large tables.
SELECT
DATEADD(day, -1, DATEADD(month, DATEDIFF(month, 0, GETDATE()), 0))
SELECT
DATEADD(day, -1, DATEADD(month, DATEDIFF(month, 0, GETDATE()) + 1,
0))
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Aaron" <odysseus183@hotmail.com> wrote in message
news:1184361210.176551.223620@n2g2000hse.googlegroups.com...
>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')
>
> Thanks,
> Aaron
>
Navigation:
[Reply to this message]
|