Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel order by column with data in format "Aug 2021", "Feb 2021"

I am working with this weird database structures, changing database structures is not the option, but how could I fetch data by order this columns ready_for_homes. Some of the data that are in databases are:

Aug 2021
Feb 2020,
August 2020,
Jan 2021,
November 2020

basically either they contain m Y or M Y,

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried with ->orderByRaw("STR_TO_DATE(ready_for_homes,'%M %Y') ASC"); but not ordering.

>Solution :

The issue could be that your text dates do not provide a day component. Given that the day doesn’t matter, we can arbitrarily assign each date to the first of the month:

->orderByRaw("STR_TO_DATE(CONCAT('01 ', ready_for_homes), '%d %M %Y')");
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading