bartoszbartniczak/doctrine-datetime-with-microseconds

Doctine extension that adds microseconds to \DateTime objects.

1.0.2 2021-10-01 08:35 UTC

This package is auto-updated.

Last update: 2024-03-29 03:51:22 UTC


README

Doctrine plugin to save DateTime objects with microseconds in database.

codecov

Installation

Via composer

composer require bartoszbartniczak/doctrine-datetime-with-microseconds

How does it work?

Standard Doctrine behavior

Doctrine saves \DateTime to the database correctly, but omits the microseconds, which are part of the \DateTime object.

Standard doctrine mapping:

1549735833745

The Doctrine ORM saves the date, but without microseconds:

1549735952539

In some systems this behavior is not expected. There are some situations where the microseconds are very important information, so they should be persisted.

Caution: Not every Database system supports Timestamps with microseconds.

How to use?

This library resolves problem of persisting microseconds with Doctrine.

Mapping

Instead of using standard Doctrine type datetime, you can use datetime_microseconds

example-mapping

After persisting object, you should have seen datetime value with microseconds saved.

Supported Relational Database Management Systems

  • PostgreSQL

Table of compatibility

PHP 7.2 PHP 7.3 PHP 7.4
Postgres 9 ✔️ ✔️ ✔️
Postgres 10 ✔️ ✔️ ✔️
Postgres 11 ✔️ ✔️ ✔️
Postgres 12 ✔️ ✔️ ✔️
MySQL 5.6.4+* ✔️ ✔️ ✔️
MySQL 8 ✔️ ✔️ ✔️
MariaDB 5.3+ ** ✔️ ✔️ ✔️
MariaDB 10 ✔️ ✔️ ✔️

*Microseconds are supported since version 5.6.4 [source1] [source2]

** Microseconds are supported since version 5.3 [source]

Other Relational Database Management Systems

If your RDBMS is not pointed on the list above, it does not mean that it will not work. It means that this library was not tested yet with that databse system. You can try and test it yourself, or even try contribute to this project.

  • Microsoft SQL Server - Not tested yet
  • Oracle database - Not tested yet
  • SQLite - Not tested yet