diff --git a/user_guide_src/source/models/model.rst b/user_guide_src/source/models/model.rst index c77e68cb81b8..5d9bb6ebdb4e 100644 --- a/user_guide_src/source/models/model.rst +++ b/user_guide_src/source/models/model.rst @@ -395,6 +395,18 @@ The datetime format is set in the ``dateFormat`` array of the :ref:`database configuration ` in the **app/Config/Database.php** file. +.. note:: + When you set ``ms`` or ``us`` as a parameter, **Model** takes care of second's + fractional part of the Time. But **Query Builder** does not. So you still need + to use the ``format()`` method when you pass the Time to Query Builder's methods + like ``where()``: + + .. literalinclude:: model/063.php + :lines: 2- + +.. note:: Prior to v4.6.0, you cannot use ``ms`` or ``us`` as a parameter. + Because the second's fractional part of Time was lost due to bugs. + Custom Casting ============== diff --git a/user_guide_src/source/models/model/063.php b/user_guide_src/source/models/model/063.php new file mode 100644 index 000000000000..cc75d0648421 --- /dev/null +++ b/user_guide_src/source/models/model/063.php @@ -0,0 +1,13 @@ +where('my_dt_field', $now->format('Y-m-d H:i:s.u'))->findAll(); +// Generates: SELECT * FROM `my_table` WHERE `my_dt_field` = '2024-07-28 18:57:58.900326' + +// But the following code loses the microseconds. +$model->where('my_dt_field', $now)->findAll(); +// Generates: SELECT * FROM `my_table` WHERE `my_dt_field` = '2024-07-28 18:57:58'