title: What would be the XQuery expression to count the number of seconds between two dateTimes?
body: <p>SQL query:</p>
  
  <pre><code>SELECT 
      ROUND((CAST(DATEATTRIBUTE2 AS DATE) - CAST(DATEATTRIBUTE1 AS DATE)) * 86400) AS result 
  FROM TEST_TABLE;
  </code></pre>
  
  <p>Both <code>DATEATTRIBUTE1</code> and <code>DATEATTRIBUTE2</code> are of <code>TIMESTAMP</code> type.</p>
  
  <p>I have tried and come up with the following <strong>XQuery</strong> :</p>
  
  <pre><code>fn:days-from-duration(fn:subtract-dateTimes-yielding-dayTimeDuration(
       $P_REQUEST/ns1:DATEATTRIBUTE2,$P_REQUEST/ns1:DATEATTRIBUTE1))*86400
  </code></pre>
  
  <p>But this fails for cases when the dates are same but there is difference in time.E.g. When <code>DATEATTRIBUTE1</code> is <code>2017-02-23T01:17:18.0000</code> and <code>DATEATTRIBUTE2</code> is <code>2017-02-23T01:17:20.7550</code> the SQL query returns 2 while XQuery returns 0.</p>
  
  <p>Thanks in advance for the help!</p>