Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

extjac's avatar

Google Charts

I am trying to create a simple timeline with google chart. But it seems that the date from is not working...and i tried a lot options...

this is just a simple example:

$bookings = \App\Booking::all('created_at', 'id');

foreach ($bookings as $key => $value) 
{

    $result[] = [$value->created_at->format('M d, Y H:i'), $value->id];

}

$data = json_encode($result);

but i get an error message regarding the date.

jsapi_compiled_default_module.js:213 Uncaught (in promise) Error: Type mismatch. Value Oct 22, 2020 11:52 does not match type datetime in column index 0
    at gvjs_oj (jsapi_compiled_default_module.js:213)
    at gvjs_9aa (jsapi_compiled_default_module.js:228)
    at gvjs_G.gvjs_.a_ (jsapi_compiled_default_module.js:230)
    at gvjs_G.gvjs_.Pp (jsapi_compiled_default_module.js:231)
    at drawChart (calendar:959)
0 likes
3 replies
siangboon's avatar
Error: Type mismatch. Value Oct 22, 2020 11:52 does not match type datetime in column index 0

the column expecting datetime, where the value Oct 22, 2020 11:52 is not a datetime type.... so parse it to datetime value before you passing to the column..

extjac's avatar

tried all combinations, Date or DateTime, changed the ->format() and cant make it work.

npispas's avatar

Hi @extjac you should try using Carbon::parse($date)

In order for a date to be proper datetime it must follow the format of "Y-m-d H:m:s" Therefore your date must be in the form of "2020-11-22 11:52:00" in order to be a valid datetime.

You could have a look at the following and choose accordingly: https://carbon.nesbot.com/docs/

Note: that Carbon is included in Laravel.

Please or to participate in this conversation.