title: Extract date as UNIX timestamp from already heavily formatted SQL datetime string
body: <p>I have the following piece of SQL code that does the following:</p>
  
  <ol>
  <li>Obviously looks at a datetime field (stored every 5 minutes)</li>
  <li><p>Averages and rounds above-mentioned datetime field to hour.  The result looks like this:</p>
  
  <pre><code>2012-02-11 16:00:00.000
  2012-02-11 17:00:00.000
  2012-02-11 18:00:00.000
  2012-02-11 19:00:00.000
  </code></pre></li>
  </ol>
  
  <p>And here's the code:</p>
  
  <pre><code>DATEADD(hh, DATEPART(hh, LogDetails.lastupdated), 
  DATEADD(d, DATEDIFF(d, 0, LogDetails.lastupdated), 0)) AS TimePeriod
  </code></pre>
  
  <p>This works like a charm and the related objects average out just fine. I now need to turn this datestamp into UNIX Timestamp (for Flot charting purposes).  Can someone help a bit here?  Whatever I seem to be doing isn't working, all the UNIX timestamps come in the same.</p>
  
  <p><strong>EDIT:</strong>  This is finally working !!</p>
  
  <pre><code>DATEDIFF(second, '1970/01/01 00:00:00', 
  DATEADD(hh, DATEPART(hh, LogDetails.lastupdated),
  DATEADD(d, DATEDIFF(d, 0, LogDetails.lastupdated), 0))) as UXTIME
  </code></pre>