#Casting dates in model ignores timezone

10 messages · Page 1 of 1 (latest)

elder gate
#

When using this

protected $casts = [
        'created_at' => 'datetime:d/m/Y H:i:s',
        'updated_at' => 'datetime:d/m/Y H:i:s'
    ];

in models, into database the hour from timestamp is correct, but when i retrieve the model in a request, the cast have 3 hours added (current in Argentina UTC-3), didnt change anything using APP_TIMEZONE into .env

scenic tangle
#

how is your 'timezone' in your config/app.php ?

elder gate
#

try this 'timezone' => env('APP_TIMEZONE', 'UTC') and 'timezone' => 'America/Argentina/Mendoza' but no change

elder gate
scenic tangle
#

i tried a lot of things, but have no more idea 😕

#

try php artisan config:clear after changes your config/app.php

elder gate
whole birch
#

php -i | grep timezone

hearty locust
#

So tldr, it will save it in UTC, since that's a recommended way to store dates. Then during serialization those dates will account for the timezone.