I have an array as collection and ordered it in ascending order with respect to expiry date as below:

$creditDetails = $this->_creditFactory->create()->addFieldToFilter('customer_id', 1)->setOrder('date_expires', 'asc');

I have some records which do not have any expiry date i.e NULL

I want such records to come in the collection at the end of or after the records which have some expiry date. Now, records without an expiry date are executing first.

How can I do this?

  • Have you tried ->setOrder('date_expires', 'DESC');
    – Sumit
    Sep 2, 2019 at 10:16

1 Answer 1


I think you can try something like this. After your line of code add this:

$creditDetails->getSelect()->order(['ISNULL(date_expires) asc']);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.