mendizalea's avatar

Editing milliseconds not updating database

Hello, I have a textinput, type datetime-local and with a step of .001 in which I store the date-time with milliseconds. When creating a new record I have no problems, but if, for example, I go to edit and modify only the milliseconds, it is not updated in the database. But for example if I update the seconds along with the milliseconds, then the milliseconds are updated.

Model:

protected $casts
    = [
        'start_time'   => 'datetime:Y-m-d H:i:s.v',
    ];

I have activated the mysql log and the new time does not arrive with the changed milliseconds.

I'm using filamentphp form.

0 likes
10 replies
vincent15000's avatar

Have you checked if the milliseconds are stored in the database with the right values ?

Have you checked the date and time returned by the form (dd($start_time)) ?

1 like
mendizalea's avatar

@vincent15000 Yes, the value returned by the form and the one stored in the database is correct. It only does not update when I change only milliseconds, if I change any other value along with the milliseconds it is fine.

1 like
mendizalea's avatar

@tisuchi Yes, it is for timing sports events and there may be cases in which the value needs to be changed.

1 like
tykus's avatar
tykus
Best Answer
Level 104

Is seems that the update is not considered a change and therefore start_time is not dirty.

Try setting the $dateFormat property on the model so comparisons are made down to milliseconds:

protected $dateFormat = 'Y-m-d H:i:s.v';
2 likes
tykus's avatar

@vincent15000

The storage format of the model's date columns

It is also used for comparison whenever Eloquent determines if date attributes are dirty.

1 like
vincent15000's avatar

@tykus Oh so it's only to say to Laravel which format is used in the database. Ok ok thank you.

Please or to participate in this conversation.