title: How to convert datetime to timestamp in MS SQL stored function
body: <p>There is a stored function which is called from table update trigger. Smt like this:</p>
  
  <pre><code>FUNCTION [dbo].[DateTime2ToBigInt](@dt DATETIME2(7))
  RETURNS BIGINT
  </code></pre>
  
  <p>Need to convert input datetime to unix timestamp. </p>
  
  <p>Tried <code>CONVERT( timestamp, @dt)</code> and <code>CAST(@dt AS TIMESTAMP)</code> but both result in </p>
  
  <blockquote>
    <p>"Explicit conversion from data type datetime2 to timestamp is not
    allowed."</p>
  </blockquote>
  
  <p>Of course it's possible to do by mathematics, but I can't believe, that mssql doesn't have direct convert function</p>