File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
user_guide_src/source/models Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -395,6 +395,18 @@ The datetime format is set in the ``dateFormat`` array of the
395395:ref: `database configuration <database-config-explanation-of-values >` in the
396396**app/Config/Database.php ** file.
397397
398+ .. note ::
399+ When you set ``ms `` or ``us `` as a parameter, **Model ** takes care of second's
400+ fractional part of the Time. But **Query Builder ** does not. So you still need
401+ to use the ``format() `` method when you pass the Time to Query Builder's methods
402+ like ``where() ``:
403+
404+ .. literalinclude :: model/063.php
405+ :lines: 2-
406+
407+ .. note :: Prior to v4.6.0, you cannot use ``ms`` or ``us`` as a parameter.
408+ Because the second's fractional part of Time was lost due to bugs.
409+
398410Custom Casting
399411==============
400412
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ $ model = model ('SomeModel ' );
4+
5+ $ now = \CodeIgniter \I18n \Time::now ();
6+
7+ // The following code passes the microseconds to Query Builder.
8+ $ model ->where ('my_dt_field ' , $ now ->format ('Y-m-d H:i:s.u ' ))->findAll ();
9+ // Generates: SELECT * FROM `my_table` WHERE `my_dt_field` = '2024-07-28 18:57:58.900326'
10+
11+ // But the following code loses the microseconds.
12+ $ model ->where ('my_dt_field ' , $ now )->findAll ();
13+ // Generates: SELECT * FROM `my_table` WHERE `my_dt_field` = '2024-07-28 18:57:58'
You can’t perform that action at this time.
0 commit comments