How to format date field in datatables?

Asked

Viewed 67 times

0

current code

 return datatables()->of($query->get())
                        ->addColumn('action', function($data){
                            $button = '<button type="button" name="edit" id="'.$data->id.'" class="edit btn btn-primary btn-sm">Edit</button>';
                            $button .= '&nbsp;&nbsp;';
                            $button .= '<button type="button" name="delete" id="'.$data->id.'" class="delete btn btn-danger btn-sm">Delete</button>';
                            return $button;
                        })
                        ->rawColumns(['action'])
                        ->make(true);
            }

I have a title field being rendered but with the Y/m/d format would like d/m/Y.

2 answers

1

->editColumn('vencimento_titulo', function ($data) {
            return $data->vencimento_titulo->format('d/m/Y');
    })

0

Possibly your date-time output is coming in textual format.

To solve this you can use strtotime(), which receives a textual date-time and converts to date-time Unix and function date(), which allows preference formatting.

Stay like this:

date('d-m-Y', strtotime(vencimento_titulo))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.