title: Convert Date (dd/mm/yyyy) to Excel Serial Number in JavaScript
body: <p><strong>Description</strong>: </p>
  
  <p>I am generating an Excel file using the <strong>XLSX</strong> on an <strong>Angular Project</strong> (<em>npm install xlsx</em>), but I am facing a problem showing a precise date. If I try to use JavaScript date object it somewhow loses precision and show a wrong date. It also fails if I try to use a string corresponding to 'dd/mm/yyyy'.    </p>
  
  <p>I figured out that to make the Microsoft Excel have a precise date with the format dd/mm/yyyy, you need to work with Excel Serial Format, that follows a pattern.    </p>
  
  <p>Here is some examples of this format:  </p>
  
  <ul>
  <li><strong>Date:</strong> 01/01/1900 - <strong>Serial:</strong> 1</li>
  <li><strong>Date:</strong> 02/01/1900 - <strong>Serial:</strong> 2</li>
  <li><strong>Date:</strong> 09/04/1900 - <strong>Serial:</strong> 100</li>
  <li><strong>Date:</strong> 26/09/1902 - <strong>Serial:</strong> 1000</li>
  <li><strong>Date:</strong> 08/09/1913 - <strong>Serial:</strong> 5000</li>
  <li><strong>Date:</strong> 18/05/1927 - <strong>Serial:</strong> 10000</li>
  <li><strong>Date:</strong> 24/07/1998 - <strong>Serial:</strong> 36000</li>
  </ul>
  
  <p>*You can try that on Microsoft Excel to check for more examples.  </p>
  
  <p>Above here is a prototype of the function I need, that will recevei a date (dd/mm/yyyy) and will return it's serial number equivalent.</p>
  
  <pre><code>private JSDateToExcelDate(inDate) {
     if(inDate != null) { 
     //TO DO
     }
  }
  </code></pre>
  
  <p><strong>Additional information:</strong>    </p>
  
  <p>The xlsx framework has can modify any cell telling it that value type will be Date. With that in mind all I need is a Date in Serial Number format.   </p>
  
  <p><strong>UPDATE 11/06/2019 - 20:14</strong></p>
  
  <p>I have found a solution with the following function that provides the number I want. I solved it partialy because the framework XLSX might be changing the value, because I am getting an output as "31/12/1969  21:00:16", witch I found out that is a default output related due to some invalid date.  (<em>I have created the function on a Angular Project, so it might contains specific syntax</em>)</p>
  
  <pre><code>private JSDateToExcelDate(date) {
      var temp: any;
      temp = new Date(date);
      if(date != "NaN" &amp;&amp; date != "Invalid Date") {
        var days = Math.round((temp.setHours(0,0,0,0) - &lt;any&gt;new Date(1899, 11, 30)) / 8.64e7);
        let ret:any = (days).toFixed(10);
        if(!isNaN(ret)) {
          return ret;  
        }
      }
      return '';
    }
  </code></pre>