title: DataTables: Ordering by Epoch Time
body: <p>How can I sort the dates in my datatable, which is initialized from HTML data in the DOM? My dates are epoch timestamps which I use moment.js to display as desired (example: July 17, 2017).</p>
  
  <p>I should note that using either the <strong>data-order</strong> or <strong>data-sort</strong> attr does not work (as described here: <a href="https://datatables.net/examples/advanced_init/html5-data-attributes.html" rel="nofollow noreferrer">https://datatables.net/examples/advanced_init/html5-data-attributes.html</a>)</p>
  
  <p><strong>Sample PHP:</strong> (this is part of a loop to collect all returned rows from a DB -- i then echo out the entirety of $member_return in the view)</p>
  
  <pre><code>$member_return .= '&lt;tr&gt;&lt;td&gt;'.$user-&gt;email.'&lt;/td&gt;&lt;td&gt;'.$user-&gt;first_name.'&lt;/td&gt;&lt;td&gt;'.$label-stat.'&lt;/td&gt;&lt;td&gt;'.$label-sub.'&lt;/td&gt;&lt;td&gt;'.(int)$user-&gt;created_on.'&lt;/td&gt;&lt;td&gt;--&lt;/td&gt;&lt;/tr&gt;';
  </code></pre>
  
  <p><strong>Sample HTML:</strong></p>
  
  <pre><code>&lt;tr&gt;
      &lt;td&gt;fake1@email.com&lt;/td&gt;
      &lt;td&gt;John2&lt;/td&gt;
      &lt;td&gt;Active&lt;/td&gt;
      &lt;td&gt;Active&lt;/td&gt;
      &lt;td&gt;1500317481&lt;/td&gt;
      &lt;td&gt;--&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;fake2@email.com&lt;/td&gt;
      &lt;td&gt;John2&lt;/td&gt;
      &lt;td&gt;Active&lt;/td&gt;
      &lt;td&gt;Active&lt;/td&gt;
      &lt;td&gt;1500317482&lt;/td&gt;
      &lt;td&gt;--&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
      &lt;td&gt;fake3@email.com&lt;/td&gt;
      &lt;td&gt;John3&lt;/td&gt;
      &lt;td&gt;Active&lt;/td&gt;
      &lt;td&gt;Active&lt;/td&gt;
      &lt;td&gt;1500317483&lt;/td&gt;
      &lt;td&gt;--&lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  
  <p><strong>jQuery:</strong></p>
  
  <pre><code>oTable = $('#view_members').DataTable({
      "columns": [
          { data: "email" },
          { data: "name" },
          { data: "status" },
          { data: "subscription" },
          {
              data: "date",
              type: "date",
              render: function(data){
                  return moment.unix(data).format("MMMM DD, YYYY")
              }
          },
          { "sortable": false }
      ]       
  })
  </code></pre>
  
  <p>Using this method, the dates are being sorted based on their date, example:</p>
  
  <pre><code>July 17, 2017
  July 17, 2017
  July 16, 2017
  July 15, 2017
  June 14, 2017
  etc
  </code></pre>
  
  <p>However, my issue is that its not sorting by the epoch date. In the above sample, while the first two records may have both been created on July 17, 2017, the second in that list should actually be the first based on the epoch time (again, this is a <strong>sample</strong>).</p>
  
  <p>The question:</p>
  
  <p>How can I display a date in my desired format (Month Day, Year), while sorting by the epoch timestamp?</p>