title: Difference in days between two dates in Impala
body: <p>I am trying to find a date difference In Impala. I have tried a few options. my most recent is below </p>
  
  <p><code>ABS(dayofyear(CAST(firstdate AS TIMESTAMP)-dayofyear(CAST(seconddate AS TIMESTAMP)</code></p>
  
  <p>an example of data looks like:</p>
  
  <blockquote>
    <p>firstDate:
    2017-11-25
    secondDate: 2017-11-30 </p>
  </blockquote>
  
  <p>The solution that I am looking for in the above scenario would be five. The provided code would give me this answer, but the trouble comes in when the first date is in december and the second one ends in January. </p>
  
  <blockquote>
    <p>Firstdate: 2016-12-30 seconddate:2017-12-30</p>
  </blockquote>
  
  <p>with the above code this gives me an output of 358 days,the outcome that I would want to see is 8 days. This code is only looking at what day of the year this falls on, and is not able to consider moving from year to year. I know that there is no datediff function on Impala and I've also tried using just subtraction on the two timestamps but that didn't work either. I have scoured google and have come back empty any suggestions would be greatly appreciated</p>