How to update the timezone for the timestamps (created_at and updated_at) managed by Laravel Eloquent?

前端 未结 4 1851
栀梦
栀梦 2020-12-28 21:32

I have a server in GMT but I want to update those fields ( *created_at* and *updated_at* ) to save timestamps in PST.

I\'ve already did some tests trying to accompli

4条回答
  •  被撕碎了的回忆
    2020-12-28 22:04

    I am not absolutely sure I understand if you want to change the setting of the server for future entries to the database, or if you want to update the current values in your database.

    If it is the latter, changing your server settings will not effect the current records in the database. If you want to change the values of the existing fields, you can do that with an MySQL command like:

     update `table` set created_at = (SELECT created_at) + INTERVAL 2 HOUR;
    

    Where table is the name of the database table and 2 is the offset in hours.

提交回复
热议问题