Skip to content

DOCSP-43158: carbon date values db query results #3133

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

Merged
merged 3 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions docs/eloquent-models/model-class.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ type, to the Laravel ``datetime`` type.
To learn more, see `Attribute Casting <https://laravel.com/docs/{+laravel-docs-version+}/eloquent-mutators#attribute-casting>`__
in the Laravel documentation.

This conversion lets you use the PHP `DateTime <https://www.php.net/manual/en/class.datetime.php>`__
or the `Carbon class <https://carbon.nesbot.com/docs/>`__ to work with dates
This conversion lets you use the PHP `DateTime
<https://www.php.net/manual/en/class.datetime.php>`__ class to work with dates
in this field. The following example shows a Laravel query that uses the
casting helper on the model to query for planets with a ``discovery_dt`` of
less than three years ago:
Expand All @@ -226,6 +226,13 @@ less than three years ago:

Planet::where( 'discovery_dt', '>', new DateTime('-3 years'))->get();

.. note:: Carbon Date Class

Starting in {+odm-long+} v5.0, ``UTCDateTime`` BSON values in MongoDB
are returned as `Carbon <https://carbon.nesbot.com/docs/>`__ date
classes in query results. The {+odm-short+} applies the default
timezone when performing this conversion.

To learn more about MongoDB's data types, see :manual:`BSON Types </reference/bson-types/>`
in the Server manual.

Expand Down
7 changes: 7 additions & 0 deletions docs/query-builder.txt
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ query builder method to retrieve documents from the
:start-after: begin query whereDate
:end-before: end query whereDate

.. note:: Date Query Result Type

Starting in {+odm-long+} v5.0, ``UTCDateTime`` BSON values in MongoDB
are returned as `Carbon <https://carbon.nesbot.com/docs/>`__ date
classes in query results. The {+odm-short+} applies the default
timezone when performing this conversion.

.. _laravel-query-builder-pattern:

Text Pattern Match Example
Expand Down
Loading