title: How to compare dates in a PL/SQL procedure?
body: <p>I'm a newbie in SQL programming. </p>
  
  <p>I need to make a procedure that will compare dates. The only argument in the procedure is a date typed in by the user in a Java program. I need to check if that argument (date) is before a year ago. In other words, I need to compare it with SYSDATE minus a year. If that is the case, I have to "purge" all of the tables related to "schedules" (there are 2 of them).</p>
  
  <p>So for example, say the user types 2013-04-13, my procedure has to compare it with SYSDATE - 1 year (in that case, it would be 2014-12-03). Since the value is less than today minus a year, the tables "MovieSchedule" and "ChannelSchedule" have to be purged. If the entered date was 2014-12-16, since it's now more than SYSDATE minus a year, the procedure has to send back an explicit error that I will be able to use in the Java program.</p>
  
  <p>Now, as I said I'm completely new to procedure programming in PL/SQL, so here is what I could come up with by looking up tutorials on the internet:</p>
  
  <pre><code>CREATE OR REPLACE
  PROCEDURE purge_schedule(purgeDate date) AS
  
  DECLARE
  currentDate := to_date(SYSDATE, 'YYYMMDD');
  
  BEGIN
  
      -- IF purgeDate &lt; (currentDate - 1year)
          -- delete content in "MovieSchedule" and "ChannelSchedule"
      -- ELSE
          -- return explicit error
  
  END purge_schedule;
  </code></pre>
  
  <p>I don't even know if any of this is the right way to write a procedure like I want. And as you can see, my problem is how to implement my condition in the procedure, not the logic behind it. I blame my lack of practice with the language.</p>
  
  <p>Please tell me if I have to be more specific of if you need more information in order to help me. Thank you for your help and have a nice day :)</p>