I have an Invoices table of Due dates and Paid dates. I have a 3rd column that is the time between paid and due date. I use DateTime and format to get how many days late the payment was.
$pDate = date("Y-m-d H:i:s",$paidDate);
$dDate = date("Y-m-d H:i:s",$dueDate);
$pDate = new DateTime($pDate);
$dDate = new DateTime($dDate);
$diff = $pDate->diff($dDate);
$pastDueFormat = $diff->format('%a');
I have tried change format to
$pastDueFormat = $diff->format('%d');
I have all this data in a table formatted by DataTables
$('#invoices').dataTable();
The problem is, I cant get sort to recognized 39 days as a number, or even 39 for that matter. my sort results are always
94 91 9 88 85 8....
when clearly i want 94,91,88,85,9,8.....
Looks like DataTables isn't so smart after all. You can explicitly provide the column type like this:
$('#invoices').dataTable({'columnDefs': [{'type': 'num', 'targets': 0}]});
The value of the 'targets'
key should equal the index of your column, 0-based.