CakePHP provides '2018-01-19 10:04:33.000' in created-column for sql-statement


#1

Hi guys,

I´m new in CakePHP.

I´ve got the Problem that the Insert-Statement for a new datarecord ist like this:
INSERT INTO article (item_number, created) OUTPUT INSERTED.* VALUES ('45456', '2018-01-19 10:04:33.000')

But then I get an conversion-error from mssql-server. Thats because the Mssql-Server expected the datetime-format like this: 2018-19-01 (YY-DD-MM) and not (YY-MM-DD).

Is there a way to change this?


#2

You have two options:

  1. Configure your database to use the sensible Y-m-d format instead of Y-d-m (recommended).
  2. Make a custom db type class which converts a datetime object to the string format you need and map datetime type to use your class https://book.cakephp.org/3.0/en/orm/database-basics.html#adding-custom-types