What if you cast them as timestamps in the model?
protected $casts = [
'start' => 'timestamp',
'end' => 'timestamp',
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the following columns in a MS SQL Server table:
date - date datatype with the value 2019-12-16
start - time(7) datatype with the value 07:00:00.000
end - time(7) datatype with the value 08:00:00.000
When I fetch the model from the database I get the following values:
date - Dec 16 2019 12:00:00:AM
start - Jan 1 1900 07:00:00:0000000AM
end - Jan 1 1900 08:00:00:0000000AM
I just want them returned as strings with their normal value.
Looking at this I think the issue is related to the PDO_SQLSRV driver, and I have to set the option "ReturnDatesAsStrings".
I've tried to do this in database config file:
'app' => [
'driver' => 'sqlsrv',
'url' => env('DB_URL'),
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '1433'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'prefix' => '',
'prefix_indexes' => true,
'options' => [
'returnDatesAsStrings' => true,
PDO::ATTR_STRINGIFY_FETCHES => true
],
],
But it didn't work. How can I set the returnDatesAsStrings option?
There's a github proposal related here.
Please or to participate in this conversation.