title: Writing a date from Excel VBA to a worksheet gives the wrong value
body: <p>When I write a date from VBA into an Excel worksheet, sometimes the value on the worksheet ends up being one less (one day earlier) than I expect. Here's an example that I've tested on a multiple computers with Excel 2003, 2007, and 2010. From the immediate window:</p>
  
  <pre><code>?Format(41652.9999999963, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-14 00:00:00
  
  [A1].value = CDate(41652.9999999963)
  ?Format([A1].value, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-13 00:00:00
  
  [A1].value = CDbl(CDate(41652.9999999963))
  ?Format([A1].value, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-14 00:00:00
  </code></pre>
  
  <p>What exactly triggers this?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Okay, let me be more clear that <strong>this isn't a rounding issue.</strong> If I go up or down one fraction of a second I get the correct time. It's just that if I hit near this exact number the date goes off by an entire day:</p>
  
  <pre><code>[A1].value = CDate(41652.99999)
  ?Format([A1].value, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-13 23:59:59
  
  [A1].value = CDate(41652.999999999996)
  ?Format([A1].value, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-13 00:00:00
  
  [A1].value = CDate(41652.999999999997)
  ?Format([A1].value, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-14 00:00:00
  
  [A1].value = CDate(41653.00001)
  ?Format([A1].value, "yyyy-mm-dd hh:mm:ss")
  
  &gt; 2014-01-14 00:00:01
  </code></pre>