Question and answer is powered by AnsPress.io
How can I select data from the database using DATE_FORMAT in Laravel? I want to apply DATE_FORMAT in orderBy option. So that my query select data to table date field.
My code:
<?php $data = DB::table("my table")->select("*")->orderBy('')->get(); ?>
I need help.
There have easy to use DATE_FORMAT in Laravel. Follow this example if you wan to select data using DATE_FORMAT.
Example code:
<?php $data = DB::table("my table")->select("*") ->orderBy(DB::raw("DATE_FORMAT(date_of_birth,'%m-%d')"), 'asc')->limit('4')->get(); ?>