First, don't use awful formats like 8/10/1009. On some systems, that will
be interpreted as August 10th, on others October 8th. I strongly suggest
always using YYYYMMDD for date-only literals in SQL Server.
Second, don't rely on offsets like 364 days. On leap years, your formula
will suddenly break, and while you may not miss a lot of data on New Years'
Eve depending on your business, it will still look funny in reports.
Probably the easiest way is:
@DateValue = '20090810',
@FirstDayOfRange = DATEADD(YEAR, DATEDIFF(YEAR, '19000101', @DateValue),
@LastDayOfRange = DATEADD(DAY, -1, DATEADD(YEAR, 1, @FirstDayOfRange));
However, if you are going to use these dates in a BETWEEN clause, unless you
are certain that your data will never contain a time component, much safer
AND < @FirstDayOfNextYear
On 8/10/09 6:31 PM, in article XXXX@XXXXX.COM , "Derek