September 15, 2010 at 6:49 am
Hello,
I am trying to build a report that needs to query records between Jan01 of last year through yesterdays date, last year. In other words, for today (9/15/2010) I would need 1/1/2009-9/14/2010. I am using the following for my EndDate
=DateAdd("y", -1, (Dateadd("d", -1, Today)))
It keeps pulling records from both years.
Any help for this Newbie would be appreciated.
September 15, 2010 at 8:48 am
1. Change "Today" to "GetDate()".
2. In your example, you want the date range to end on 9/14/2010. I assume this is a typo, and should be 9/14/2009?
Wayne
Microsoft Certified Master: SQL Server 2008
Author - SQL Server T-SQL Recipes
September 15, 2010 at 9:31 am
You should use
select dateadd(yy,-1,dateadd(d,-1,getdate()))
September 15, 2010 at 6:17 pm
Dung Dinh (9/15/2010)
You should use
select dateadd(yy,-1,dateadd(d,-1,getdate()))
Agreed... now all you need to do is to provide the other needed date. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
September 15, 2010 at 6:20 pm
WayneS (9/15/2010)
1. Change "Today" to "GetDate()".2. In your example, you want the date range to end on 9/14/2010. I assume this is a typo, and should be 9/14/2009?
I've got the sneaky feeling that this is going to be for an SSRS report which would explain "Today" I think...
Anyway, I agree... the op needs to clarify what the date range should actually be.
--Jeff Moden
Change is inevitable... Change for the better is not.
September 16, 2010 at 5:35 am
My apologies and thanks for the help. It is for SSRS. The date range should have been described as January 1st of last year (1/1/2009) through yesterdays month/day/lastyear. This would be for a report parameter EndDate.
edited for mistake
September 16, 2010 at 9:05 am
If there is a report parameter. The fomular will be
=DateAdd("yyyy",-1,DateAdd("d",-1,Today()))
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply