title: How to convert datetime (SQL Server) into Excel datetime?
body: <p><strong>The problem</strong>: I would like to convert <code>datetime</code> of SQL Server into Excel datetime format.</p>
  
  <p>Example 1: from <code>2018-08-23 15:32:32.000</code> to <code>43335,65</code></p>
  
  <p>Example 2: from <code>1985-03-26 10:35:42.000</code> to <code>31132,44</code></p>
  
  <p>What I have tried: inspired by <a href="https://stackoverflow.com/a/13850777/1008588">this</a> answer, I tried this query</p>
  
  <pre><code>SELECT DATEDIFF(day, @MyDatetime, GETDATE())
  </code></pre>
  
  <p>which works if you want to convert a date (without the hours), but how to convert the time too?</p>
  
  <p>In Excel, the time is saved in the decimal part of the number so I've tried to use </p>
  
  <pre><code>SELECT DATEDIFF(SECOND, '1899/12/30 00:00:00.000', GETDATE())
  </code></pre>
  
  <p>but this results in an overflow error.</p>
  
  <blockquote>
    <p>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>
  </blockquote>