title: Difference in Days in DB2
body: <p>I have to calculate the difference in days between two dates and I figured out that
  there is no such thing as a <code>DATEDIFF()</code> function in DB2.</p>
  
  <p>I tried doing it like that:</p>
  
  <pre><code>(DAYOFYEAR(date1)-DAYOFYEAR(date2)+(YEAR(date1)-YEAR(date2))*365)
  </code></pre>
  
  <p>This is obviously not working for leap years, but I do not have to deal with that. </p>
  
  <p>I know that date1 is always later than date2.</p>
  
  <p>Do I have any flaws in my logic? It is not working (it's an exercise and I have a function to test my results). Is there an easier way to do that?</p>
  
  <p>Thank you.</p>