dimanche 17 juillet 2016

Laravel 5 How to convert date related column using Carbon in select clause?

I am new to php and laravel and using laravel 5.2 with MariaDB 10.1.xx. test table has index and date (yyyymmdd) columns. I would like to convert date format from yyyymmdd to YYYYmm without using raw query in the select clause. I tried it as following: $test = DB::table('test') ->select( 'idx',Carbon::parse('date')->format('Ym') ); and got error as below: DateTime::__construct(): Failed to parse time string (date) at position 0 (n): The timezone could not be found in the database. Please let me have any idea to solve this issue using carbon not raw query.

Aucun commentaire:

Enregistrer un commentaire