Syntax help - Subtract two years from current date?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • KA NMC
    New Member
    • Aug 2007
    • 40

    Syntax help - Subtract two years from current date?

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

    Code:
    select oe_hdr.customer_id
    from oe_hdr
    where year (oe_hdr.order_date) >= year (getdate()-2 )
    Thanks
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    Originally posted by KA NMC
    I need help with the syntax below to subtract two years from the current date

    Code:
    select oe_hdr.customer_id
    from oe_hdr
    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,get date()) - 2


    -- ck

    Comment

    • KA NMC
      New Member
      • Aug 2007
      • 40

      #3
      Thanks especially for the technet.

      Originally posted by ck9663
      use datepart

      something like:

      select oe_hdr.customer _id
      from oe_hdr
      where datepart(yy,oe_ hdr.order_date) >= datepart(yy,get date()) - 2


      -- ck

      Comment

      Working...