Laravel 5.4 - "DB:raw()" using MySQL "CAST()" function

Viewed 5412

I'm trying to submit a DB:raw() query, to test the MySQL CAST() function.

My Model contains:

class User extend Model
{
   public static function myMethodDate()
   {
        $var = DB::select(
                  DB::raw("SELECT CAST('2017-05-24 13:38:35.471001' AS DATETIME(3)) AS arrival_time")
               );
        dd($var[0]->arrival_time);
   }
}

when I call the myMethodDate() method, It returns:

"2017-05-24 13:38:35"

but If I run It on MySQL shell:

mysql>
mysql> SELECT CAST('2017-05-24 13:38:35.471001' AS DATETIME(3)) AS arrival_time;
+-------------------------+
| arrival_time            |
+-------------------------+
| 2017-05-24 13:38:35.471 |
+-------------------------+
1 row in set (0.00 sec)

mysql>

with "milliseconds".

Why the Laravel DB:raw() query does not report the MySQL CAST() output?

Thank you.

2 Answers
Related