Framework: Add DateTime milliseconds to database Grammar bindings

Created on 6 Nov 2020  路  7Comments  路  Source: laravel/framework

Laravel Version: 8.13.0
PHP Version: 7.4.11
Database Driver & Version: default Laravel installation PDO, MySQL 5.7

https://github.com/laravel/framework/blob/8550bac5cf4d9e8d52296c1f6d93bbf7f4596002/src/Illuminate/Database/Grammar.php#L189-L197
As a DateTime column precision could be stored in a database it is convenient to change query format binding to Y-m-d H:i:s.u

Most helpful comment

You can already modify this format on your models by setting the $dateFormat property:

protected $dateFormat = 'Y-m-d H:i:s.u';

All 7 comments

This isn't necessary.

This isn't necessary.

@driesvints I can't agree. It is necessary to query rows that contain milliseconds. And without this change, you are unable to implement precise time-based cursor pagination.

@TeroBlaZe most of the datetime columns are timestamps which are in seconds, not miliseconds.

@driesvints Maybe so but you also could use the TIMESTAMP precision option to add milliseconds and microseconds but you unable to filter on it because of this query format. There should be an option to support this format as you need it. What do you think?

You can already modify this format on your models by setting the $dateFormat property:

protected $dateFormat = 'Y-m-d H:i:s.u';

You can already modify this format on your models by setting the $dateFormat property:

protected $dateFormat = 'Y-m-d H:i:s.u';

Why do you think I'm talking about eloquent and models? This variable can do nothing with DB's queries. There's a place that does a thing.
https://github.com/laravel/framework/blob/a9af73f4bac48ea29d49d918c52a41628089358c/src/Illuminate/Database/Connection.php#L587-L609

I think the issue was closed without a reason so please reopen it so anyone else can see it. Maybe someone can provide a better solution than mine.

We're not changing this, sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

SachinAgarwal1337 picture SachinAgarwal1337  路  3Comments

kerbylav picture kerbylav  路  3Comments

shopblocks picture shopblocks  路  3Comments

iivanov2 picture iivanov2  路  3Comments

jackmu95 picture jackmu95  路  3Comments