Techgenz India
Techgenz India

Reputation: 33

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.

Upvotes: 3

Views: 7276

Answers (1)

aynber
aynber

Reputation: 23011

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();

Upvotes: 3

Related Questions