Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display only date from datetime in laravel

I just write a query to fetch some data from a table in Laravel but in the frontend, I need to display only date not a time

            $table_lastRecords = DB::table($table_name)
                        ->join('lead_status', $status_dbvariable, '=', 'lead_status.status_id')
                        ->join('users', $user_dbvariable, '=', 'users.id')
                        ->select('enquiry_id','yourname',''.$table_name.'.phone','status_title as status','name', 'submitted')->where('name', $user_id)->get();

Where "submitted" store the DateTime but I only want to display the date in frontend. I can't do anything frontend because I use data tables and using loop I just get the data.

Any suggestion for query please let me know how can I achieve it thanks for your time.

like image 306
Techgenz India Avatar asked Dec 21 '25 18:12

Techgenz India


1 Answers

You can use DB::raw() to pass in a MySQL function to get the formatted date.

->select('enquiry_id','yourname', $table_name.'.phone','status_title as status','name', DB::raw('DATE(submitted) AS submitted'))
->where('name', $user_id)->get();
like image 177
aynber Avatar answered Dec 23 '25 10:12

aynber