title: Convert Sql Server DateTime to Milliseconds Since 1970
body: <p>I want to convert sql server datetime to milliseconds . I tried to convert it with datediff function as below :</p>
  
  <pre><code>select cast(Datediff(ms, '1970-01-01',GETUTCDATE()) AS bigint)
  </code></pre>
  
  <p>But it's giving me this error:</p>
  
  <p>Msg 535, Level 16, State 0, Line 2
  The datediff function resulted in an overflow. The number of dateparts separating two date/time instances is too large. Try to use datediff with a less precise datepart.</p>
  
  <p>I don't wanna do it like this :</p>
  
  <pre><code>select cast(Datediff(minute, '1970-01-01',GETUTCDATE()) AS bigint)*60*1000
  </code></pre>
  
  <p>Because it won't give me accurate results. Can somebody please help me on this? </p>