简体   繁体   中英

Laravel strange date formatting

I inherited a Laravel project and am running into a strange issue with date formatting.

I get the following error:

InvalidArgumentException in Carbon.php line 582

Unexpected data found.

Unexpected data found.

The separation symbol could not be found

Unexpected data found

Trailing data

The stack track shows the problem has to do with a date time conversion:

at Carbon::createFromFormat('Ymd H:i:s.u', 'Oct 10 2017 02:31:04:493PM') in Model.php line 3003

I can see that there is a weird date format with 02:31:04:493PM as the time. I don't know where that format is coming from and I've spent literally all day trying.

All of the date formats in the application code are of the 'Ymd H:i:su' or 'Ymd H:i:s' format. I don't know where this invalid one with the : before microseconds is coming from and I can't seem to find it anywhere in the code.

I've checked in Model.php, Carbon.php, all of the app Models that inherit from Model, etc. When I run the project on localhost environment, everything loads fine, but when I try on the dev environment, this error happens.

The leads me to believe it is something environment specific, but I don't know enough about Apache/PHP/SQL Server to know where the formatting is coming from. The data in the database appears just fine as normal datetime values.

Any ideas or suggestions on where to look?

The issue was resolved by migrating our PHP server from FreeBSD to IIS.

Our environment did not have the appropriate PDO SQLSRV drivers to communicate to our SQL Server database properly and Microsoft doesn't provide pre-compiled versions for FreeBSD.

Our organization did not need to use FreeBSD and so we moved to IIS because it was easier for our new members to manage. With IIS, we were able to download the Microsoft PDO SQLSRV drivers that are compiled for IIS/Windows and this made the DB queries yield the correct date formats.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM