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

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]


Удаленная работа для программистов  •  Как заработать на 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

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