Link to home
Start Free TrialLog in
Avatar of LoriLHS
LoriLHS

asked on

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.
Avatar of Sara bhai
Sara bhai
Flag of India image

Did you need records between 1 April to 31 March.
Avatar of LoriLHS
LoriLHS

ASKER

All of current year up til today.
It means, suppose todays u need records from 1 jan 2011 to 5 april 2011.

Use GETDATE()


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


ASKER CERTIFIED SOLUTION
Avatar of Ephraim Wangoya
Ephraim Wangoya
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of LoriLHS

ASKER

Thank you.
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())) )