title: Teradata timestamp subtraction with difference in minutes
body: <pre><code>select StartDatetime,EndDatetime,
  (TRIM((COALESCE(CAST((CAST(EndDatetime AS TIME) - CAST(StartDatetime AS TIME) MINUTE(4)) AS INT),'')))) as TimeDiff
  From Table1
  </code></pre>
  <p><code>EndDatetime</code> and <code>StartDatetime</code> are columns of type <code>Timestamp(6)</code>. The above query gave the difference in between the timestamps in minutes. It is working if both the timestamps are present in the same day. But when <code>EndDatetime</code> is having a value of tomorrow wrt to the <code>StartDatetime</code> then the TimeDiff value that is being returned is a negative value. Using absolute function is not a best solution because then the TimeDiff number itself isn't accurate.</p>
  <p>How to get the timestamp difference precisely in minutes?</p>