Level 73
You can use TO_CHAR
SELECT DISTINCT TO_CHAR(date, 'YYYY-MM') FROM table;
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
here is my code. its working fine.
SubjectReport::selectRaw('YEAR(date) as year, MONTH(date) as month')->distinct()->get();
I want to know is it another way to get data from database using eloquent or collection methods?
example:
2023-01
2023-02
2023-03
thanks.
Please or to participate in this conversation.