B Woods
B Woods

Reputation: 580

How to get 6 months from a parametrized date

I have a where clause where I am trying to get a date within a certain range with parameters like so,

 (AL.INSERTED_DATE BETWEEN (:begindate) AND (:enddate))

The problem is that I need to get six months before the begin date but I get an error, ORA-00904: "DATEADD": invalid identifier, when I try,

 (AL.INSERTED_DATE BETWEEN DATEADD(Month,-6,(:begindate)) AND (:enddate))

Can anybody point me out to what I could be doing wrong?

Upvotes: 1

Views: 119

Answers (2)

Sir Pakington Esq
Sir Pakington Esq

Reputation: 583

You're not using SQL Server, you're using Oracle - that's why it's giving you an error in Oracle format.

http://psoug.org/definition/ADD_MONTHS.htm

ADD_MONTHS would probably be the best equivalent to what you're trying to do here -

  (AL.INSERTED_DATE BETWEEN ADD_MONTHS((:begindate),-6) AND (:enddate))

Upvotes: 1

BWS
BWS

Reputation: 3836

Check this solution:

Oracle (10g) equivalent of DATEADD(weekday, -3, GETDATE())

Upvotes: 0

Related Questions