title: SQL query-How to calcucate average time difference from two dates in format : 5 days 13 hours
body: <p>I wrote SQL expression in format:</p>
  
  <pre><code>    select date1,date2,
  cast ( Floor ( timestampdiff   (4, char (     timestamp (DATE2)-  
       timestamp (DATE1)))/1440) as char (3))||'days' ||' '  
   || cast ( Floor ( Mod ( timestampdiff (4, char(   timestamp (DATE2)-  
       timestamp (DATE1))) , 1440) / 60) as char (3)) ||'hours' 
  </code></pre>
  
  <p>So I am having difference in minutes and then transforming it to days and hours.
  Example result will be:</p>
  
  <pre><code>DATE1                  DATE2                  DIFFERENCE
  2012-01-01 10:00:00    2012-01-03 12:00     2 days 2 hours
  2012-01-03 11:00:00    2012-01-03 12:00     0 days 1 hours
  </code></pre>
  
  <p>This is result which I am getting at the moment and it is ok.
  But now I want to have seperate result with AVERAGE value for difference.
  So for first row number of minutes is 3000.
  For second row number of minutes is 60.
  Average value is (3000+60)/2=1530 = 1 days 1 hours   </p>
  
  <p>So I want result in this format: average value: "1 days 1 hours"</p>
  
  <p>I am using db2.
  Thank you</p>