0

I am trying to make a constraint to ensure that the finishdate is at least 3 years greater than the startdate.

I have had a look around but really do not know where to start?

Would i need to use a dateadd function?

Thanks

  • Oracle doesn't have `dateadd`. You're probably looking for `add_months`. Since you've tagged it with check-constraints you do seem to know where to start, so have you tried to add a constraint? It might help to show your existing table structure and your best attempt so far, and why it was wrong. – Alex Poole Apr 20 '16 at 13:13

1 Answers1

2

You could do it a number of ways, but since you asked about check constraints, something like this should work:

CREATE TABLE myTable
(
  id numeric(4),
  startdate date,
  finishdate date,
  CONSTRAINT check_date
  CHECK (finishdate >= add_months( startdate , 36 ))
);
StevieG
  • 8,639
  • 23
  • 31
  • Hi there, thank you for that I actually tried something very similar and it just seemed to me the wrong syntax. –  Apr 20 '16 at 13:18