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

tomhamx's avatar

Exception thrown with message "DateTime::__construct(): Failed to parse time string

Hi everybody,

I'm running through the great series Laravel 5.4 from scratch. I run a server on a Raspberry Pi 3 running Raspbian and followed along some lessons, all going well.

Today, I just re-started "php artisan serve" and I get the error (and the entire stacktrace) below...

Nothing changed, and I wasn't that far in the training so just returning some lines from a db directly from routes... I tried a "composer dump-autoload", I thought it were the timestamps in my db, so I removed them by changing the migration but no luck.

If I understand the info below it has something to do with the session, not with the data I'm passing. However I don't know how to fix this. I've found some stuff on SO but all answers suggest adapting some code but I think this has nothing todo with coding but something on my server?

Anyone got a clue what the heck is wrong here? It worked before...

Exception thrown with message "DateTime::__construct(): Failed to parse time string (2018-03-14 21:13:35.-325792) at position 24 (7): Unexpected character"

Stacktrace:
#45 Exception in /home/pi/projects/books/vendor/nesbot/carbon/src/Carbon/Carbon.php:408
#44 DateTime:__construct in /home/pi/projects/books/vendor/nesbot/carbon/src/Carbon/Carbon.php:408
#43 Carbon\Carbon:__construct in /home/pi/projects/books/vendor/nesbot/carbon/src/Carbon/Carbon.php:457
#42 Carbon\Carbon:now in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/FileSessionHandler.php:70
#41 Illuminate\Session\FileSessionHandler:read in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/Store.php:96
#40 Illuminate\Session\Store:readFromHandler in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/Store.php:86
#39 Illuminate\Session\Store:loadSession in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/Store.php:70
#38 Illuminate\Session\Store:start in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:102
#37 Illuminate\Session\Middleware\StartSession:Illuminate\Session\Middleware\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Support/helpers.php:1038
#36 tap in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:103
#35 Illuminate\Session\Middleware\StartSession:startSession in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:57
#34 Illuminate\Session\Middleware\StartSession:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#33 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#32 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37
#31 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#30 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#29 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59
#28 Illuminate\Cookie\Middleware\EncryptCookies:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#27 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#26 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
#25 Illuminate\Pipeline\Pipeline:then in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Router.php:660
#24 Illuminate\Routing\Router:runRouteWithinStack in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Router.php:635
#23 Illuminate\Routing\Router:runRoute in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Router.php:601
#22 Illuminate\Routing\Router:dispatchToRoute in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Router.php:590
#21 Illuminate\Routing\Router:dispatch in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176
#20 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30
#19 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/fideloper/proxy/src/TrustProxies.php:56
#18 Fideloper\Proxy\TrustProxies:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#17 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#16 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
#15 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#14 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#13 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30
#12 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#11 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#10 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27
#9 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#8 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#7 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46
#6 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149
#5 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53
#4 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102
#3 Illuminate\Pipeline\Pipeline:then in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151
#2 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /home/pi/projects/books/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116
#1 Illuminate\Foundation\Http\Kernel:handle in /home/pi/projects/books/public/index.php:55
#0 require_once in /home/pi/projects/books/server.php:21
0 likes
8 replies
deansatch's avatar

It’s this - date has some negative number appended:

"DateTime::__construct(): Failed to parse time string (2018-03-14 21:13:35.-325792) at position 24 (7): Unexpected character"

Let’s see the code

tomhamx's avatar

Im sorry, but what code? All I do is fetch all lines from a tasks table with the query builder and return. It returned JSON (as it should) yesterday...

Every time I refresh the time stamp on the error message is the current server time, so unrelated to the time stamp in my tasks db I figured?

deansatch's avatar

Does this happen on all routes? What if you just try and return a string instead of your query?

click's avatar

I don't think this has anything todo with a query or whatever route. What does the following output on your console?

type in your webroot: php artisan tinker and than type: new \DateTime('now');

What does that give you?

tomhamx's avatar

@deansnatch I'll try the rollback tonight and keep you all posted. It happens on all routes, unfortunately. Even on return "Hello World"

@m-rk

new \DateTime('now');

=> DateTime @1521093438 {#737
     date: 2018-03-15 05:57:18.0 UTC (+00:00),
   }
tomhamx's avatar

Hi all, thanks for the help! I've forced Carbon to v1.24.2 (it was 1.24.1 with an issue with "negative values in microtime"

Thanks for pointing me in the right direction!!!

Please or to participate in this conversation.