# How do I pull records for the current year using the system date?

How do I pull records for the current year (2011) using the system date?  And for the prior and current year (2010 & 2011) using the system date.
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
Did you need records between 1 April to 31 March.
0
Author Commented:
All of current year up til today.
0
Commented:
It means, suppose todays u need records from 1 jan 2011 to 5 april 2011.
0
Commented:

Use GETDATE()

select * from yourtable
where DATEPART(YEAR, yourdatefield) = DATEPART(YEAR, GETDATE())

0
Commented:

select * from yourtable
where DATEPART(YEAR, yourdatefield) = DATEPART(YEAR, GETDATE())  --this year
or DATEPART(YEAR, yourdatefield) = DATEPART(YEAR, DATEADD(YY, -1, GETDATE()))  --last year
0

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Author Commented:
Thank you.
0
Commented:
try this one...
select * From T_table
where d_column between convert( datetime , convert(char(4),year(getdate())) +'-'+ convert(char(4), '1')+'-' + convert(char(4),'1') )
and convert( datetime , convert(char(4),year( getdate())) +'-'+ convert(char(4),month( getdate()))+'-' + convert(char(4),day( getdate())) )
0
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.