0

I am trying this simple sql query

SELECT DATE_FORMAT(my_date, '%m-%d-%Y') FROM my_tbl WHERE id = 1

in Eloquent like

$tbl = DB::table('my_tbl');
$tbl->select( 'DATE_FORMAT(my_date, "%m-%d,-%Y")' );
$tbl->where( 'id', "=", 1);
Datatable::query($tbl);

but it accepts as string and throws error:

{"error":{"type":"Illuminate\\Database\\QueryException","message":"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'DATE_FORMAT(arrival, \"%d %M, %Y\")'

1 Answer 1

1

Okay I just add DB::raw and it worked :)

$tbl->select( 'DB::raw('DATE_FORMAT(my_date, \'%m-%d-%Y\') AS arrival')' );
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.