By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,453 Members | 959 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,453 IT Pros & Developers. It's quick & easy.

Syntax help - Subtract two years from current date?

P: 40
I need help with the syntax below to subtract two years from the current date

Expand|Select|Wrap|Line Numbers
  1. select oe_hdr.customer_id
  2. from oe_hdr
  3. where year (oe_hdr.order_date) >= year (getdate()-2 )
Thanks
Feb 8 '08 #1
Share this Question
Share on Google+
2 Replies


ck9663
Expert 2.5K+
P: 2,878
I need help with the syntax below to subtract two years from the current date

Expand|Select|Wrap|Line Numbers
  1. select oe_hdr.customer_id
  2. from oe_hdr
  3. where year (oe_hdr.order_date) >= year (getdate()-2 )
Thanks

use datepart

something like:

select oe_hdr.customer_id
from oe_hdr
where datepart(yy,oe_hdr.order_date) >= datepart(yy,getdate()) - 2


-- ck
Feb 8 '08 #2

P: 40
Thanks especially for the technet.

use datepart

something like:

select oe_hdr.customer_id
from oe_hdr
where datepart(yy,oe_hdr.order_date) >= datepart(yy,getdate()) - 2


-- ck
Feb 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.