Sample data:
sDate NAME
2010-03-28 Andrew
2011-05-10 Drew
2010-04-11 Clary
2009-12-26 Kriz
I want to sort it out so that the output will only show those that arefrom 01/01/11 to the year to date. Is there an automatic syntax so that I will not change my sql statement to the date today but it will always show the year to date?
Example of my statement:
SELECT *
FROM 'mytable'
Where sDate BETWEEN '2011-01-01' AND '2011-08-09'
No hardcoding of dates is needed. DATEADD(yy, DATEDIFF(yy,0,GETDATE()), 0) will give you the first day of the current year. So:
...WHERE sDate BETWEEN DATEADD(yy, DATEDIFF(yy,0,GETDATE()), 0) AND GETDATE()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With