7

In a MySQL database I have a datetime field stored like this:

2015-05-12 13:58:25.000508

But when I execute this query, for example:

    $query = SdkEvent::with('sdkEventStack');

            if (isset($params['CO_ID']) && $params['CO_ID'] != "") {
                $query->where('CO_ID', $params['CO_ID']);
            }

            if (isset($params['APP_ID']) && $params['APP_ID'] != "") {
                $query->where('APP_ID', $params['APP_ID']);
            }

            if (isset($params['app_ip']) && $params['app_ip'] != "") {
                $query->where('SDKEVENT_IP', 'LIKE', $params['app_ip'].'%');
            }

            if (isset($params['PLACE_ID']) && $params['PLACE_ID'] != "") {
                $query->where('PLACEMENT_ID', $params['PLACE_ID']);
            }

    $sdks = $query->get();

I get the datetime like this: 2015-05-12 13:58:25 Why am I not getting the microseconds ?

1
  • What type of datetype do you have it stored as in MySQL? Commented May 28, 2015 at 17:47

1 Answer 1

1

It isn't an issue with Laravel, it is an issue with PDO, which Laravel uses for making database queries.

For more info see this other question: PHP How to return datetime(6) from Mysql?

or the actual bug report

http://grokbase.com/t/php/php-bugs/11524dvh68/php-bug-bug-54648-new-pdo-forces-format-of-datetime-fields

You can pull microseconds by using a DB::select() statement. For example:

$test = DB::select("SELECT id, DATE_FORMAT(date, '%Y-%m-%d %H:%i:%f') as date FROM test");
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.