Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid date format generated from Carbon::now() when updating SQL server #25388

Closed
beard7 opened this issue Aug 31, 2018 · 2 comments
Closed

Comments

@beard7
Copy link

beard7 commented Aug 31, 2018

  • Laravel Version: 5.6.24
  • PHP Version: 7.1.3
  • Database Driver & Version: SQL Server

Description:

Occasionally database updates and inserts fail with Conversion failed when converting date and/or time from character string because the date format generated from Carbon::now() is incorrect.

I say occasionally, because it looks like the chances of this occuring are slim, but it is happening. For example, this is the query generated for an update where the dates in the model are both set to Carbon::now()
update [Table] set [FirstDate] = '2018-08-31 10:32:23.999', [SecondDate] = '2018-08-31 10:32:23.1000' where [Id] = 13381
Note the format of the SecondDate... it's not valid, surely it should be 2018-08-31 10:32:24.000

Steps To Reproduce:

Obviously this is tricky, as it seems to rely on performing and insert or update at exactly 0.999 of a second.

I've done a workaround by fixing all the formats used during updates and inserts using Carbon::now()->format('Y-m-d H:i:s') or Carbon::now()->format('Y-m-d'), but this is a bit of a pain.

I wish I didn't have to use SQL server, but this is a new front end to a legacy system, so I've no choice.

@staudenmeir
Copy link
Contributor

See #22407. Can you upgrade to PHP 7.2?

@laurencei
Copy link
Contributor

As @staudenmeir said, see the other thread for a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants