November 10, 2008 at 10:09 am
I have this AND clause:
AND c.DateCreated BETWEEN DATEADD(YEAR, -5, GETDATE())
Is this correct? What I am trying to get to is any records from today to 5 years ago.
Warm Regards,
Arthur Lorenzini
Sioux Falls, SD
November 10, 2008 at 10:17 am
Arthur.Lorenzini (11/10/2008)
I have this AND clause:AND c.DateCreated BETWEEN DATEADD(YEAR, -5, GETDATE())
Is this correct? What I am trying to get to is any records from today to 5 years ago.
No, you are missing part of the between and you'll lose records because of the time. I'd change it to this:
AND c.DateCreated >= dateadd(yy, -5, dateadd(dd, datediff(dd, 0, getdate()), 0) )
AND c.DateCreated < getdate()
November 10, 2008 at 10:17 am
well other than the fact that you missing half the BETWEEN statement I would say yes almost there.
c.Date > = DATEDIFF(yy,-5,GETDATE())
Please not the this will take into account time as well.
Thanks
Chris
----------------------------------------------
Try to learn something about everything and everything about something. - Thomas Henry Huxley
:w00t:
Posting Best Practices[/url]
Numbers / Tally Tables[/url]
November 10, 2008 at 10:32 am
Hi Arthur
It depends, i would use >datadiff 🙂
November 10, 2008 at 12:38 pm
CrazyMan (11/10/2008)
Hi ArthurIt depends, i would use >datadiff 🙂
And would be wrong.
_____________
Code for TallyGenerator
November 10, 2008 at 1:50 pm
Christopher Stobbs (11/10/2008)
well other than the fact that you missing half the BETWEEN statement I would say yes almost there.
c.Date > = DATEDIFF(yy,-5,GETDATE())
Please not the this will take into account time as well.
Thanks
Chris
You'd want to use this, and it still has the issue with the time portion:
c.Date > = DATEADD(yy,-5,GETDATE())
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply