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

SmoDav's avatar

Default date format

Hi guys, I'm having a problem with the date format when developing for SQL Server. When using the DBLib extension the format breaks, when using the sqlsrv extension, it works. One could argue that changing the date format on the models would help, he would actually be right, but other packages that extend on Eloquent Model like Passport actually break and modifying the Eloquent Model class is wrong. Is there a way to change the global date format that is used throughout the system?

0 likes
12 replies
SmoDav's avatar

What about the packages that use Eloquent? Like Passport? Editing the package will revert the changes once the package is updated

SmoDav's avatar

@bobbybouwmann I still don't get you. My current problem is that I can't create any tokens due to carbon throwing an invalid arguments exception. All models I have used to throw the same exception. For the models, they extend an abstract class that extends Eloquent model with the date format set. Is there any way to fix the date format in the packages without editing them?

SmoDav's avatar

@bobbybouwmann the expected SQL Server date format is

protected $dateFormat = 'Y-m-d H:i:s';

but what the query grammar is giving is

protected $dateFormat = 'Y-m-d H:i:s.000'

The Laravel\Passport\Token model will use the builder grammar since it directly extends Model. @JeffreyWay any way to sort this without modifying the package?

1 like
bobbybouwmann's avatar

Like I said you use a trait. You clearly have no idea what a trait is: http://php.net/manual/en/language.oop5.traits.php

A trait is some kind of class that can be included in many places. So in this case if you a method in it that's the same as the extended class it will override that. So you can override the basic behaviour of the Eloquent class with that trait.

SmoDav's avatar

@bobbybouwmann I understand what a trait is and they help a lot with multiple inheritance. The problem is changing the packages. If I include the trait in the Laravel\Passport\Token model, I would have modified the package. When it is updated, it will revert all changes that I made thus, its always a bad idea to modify packages. The trait would work on the Models I create without any problem since I maintain them.

bobbybouwmann's avatar

Aah I didn't understood that you wanted to replace the Token model in the passport package. I think you should create an issue on Github since this is a package specific problem

SmoDav's avatar

@bobbybouwmann exactly. The problem is with these packages that are maintained by other people. If in app.config we could set the default date format to be used across Laravel, the issue would be sorted. Thanks though.

1 like
bobbybouwmann's avatar

Just create the issue and see what will happen ;) I will keep an eye on the issue once it's created ;)

amcsi's avatar

@smodav have you created the issue? I'd be curious what its state is.

Please or to participate in this conversation.