0

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.....

1
  • You've to deal with the datatable, because its responsible for the column sorting, its sorting that column as if its string but not number, I got this problem, the solution I've done is that I changed - in the datatable config js code - the column which sorting would be based on! Commented Feb 19, 2015 at 12:57

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.