Carbon::now() and now() return the wrong hour in Laravel
now() prints a time several hours behind or ahead of the wall clockShort answer
Carbon::now() uses the PHP default timezone, and Laravel sets that from app.timezone in config/app.php on every boot. If the hour is off, the config value is not what you think: it is still UTC, an old cached config is in use, or the code runs outside the framework where php.ini decides.
Fix it fast
1Find out which cause you have
Compare what Laravel thinks the timezone is with what PHP is using. If the two differ, something runs outside the framework.
php artisan config:show app php -r "echo date_default_timezone_get(), PHP_EOL;"2Match what you see, then jump to its fix
- 1
config:show app lists timezone as UTC.app.timezone is still UTCFix - 2
config/app.php shows the right timezone but config:show app or the site still shows the old one.The config cache holds the old valueFix - 3
date_default_timezone_get() from a plain PHP script differs from app.timezone.The code runs outside Laravel, so php.ini decidesFix
- 1
What does the error look like?
now() prints a time several hours behind or ahead of the wall clockcreated_at values do not match the local time
Cause 1 of 3
app.timezone is still UTC
1Check
Laravel reads the timezone option of config/app.php and passes it to PHP's date_default_timezone_set() while it loads configuration, with UTC as the fallback.
grep -n "timezone" config/app.php2Fix
Set the timezone you want to your own region in config/app.php, then clear the cache so it is picked up.
// config/app.php
'timezone' => 'Europe/Berlin',3Verify
Run the first-step command again; the timezone now shows the new value.
php artisan config:show appConfirmed by raw.githubusercontent.com
Cause 2 of 3
The config cache holds the old value
1Check
After config:cache, Laravel loads the one cached file and does not read your edited config files or .env on later requests.
ls -l bootstrap/cache/config.php2Fix
Clear the cached configuration, and if you cache on deploy, rebuild it after the edit.
php artisan config:clear
php artisan config:cache3Verify
Print the value again.
php artisan config:show appConfirmed by laravel.com
Cause 3 of 3
The code runs outside Laravel, so php.ini decides
1Check
PHP picks its default timezone from date_default_timezone_set() if called, then the date.timezone ini setting, and falls back to UTC. A standalone script, a cron job calling php directly or a test bootstrap never runs Laravel's config loading.
php -i | grep -i "date.timezone"
php --ini2Fix
Set date.timezone in the php.ini that CLI and FPM load, or call date_default_timezone_set() at the start of the script.
; php.ini
date.timezone = Europe/Berlin3Verify
Run the plain PHP one-liner again.
php -r "echo date_default_timezone_get(), PHP_EOL;"Confirmed by php.net
How do I stop it coming back?
- Keep app.timezone on UTC for stored data if you serve several regions, and convert only when you show a time to a person.
- Run config:clear after every change to config/app.php on a server that caches config.
- Set date.timezone in php.ini on servers so scripts outside Laravel agree with the app.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
DateTimeZone::__construct(): Unknown or bad timezone
Uncaught DateInvalidTimeZoneException (PHP 8.3 and later)
PHP throws this when the string is not a valid timezone identifier, UTC offset or abbreviation.
3 causes, each with a fixBack end
Composer says the gd extension is missing on a Laravel project
composer install or composer update stops on a package that requires ext-gd
Composer refuses to install a package that requires ext-gd when the PHP binary running Composer has no GD extension.
4 causes, each with a fixBack end
Why a Filament panel feels slow on a Laravel server
The panel is fast on a small demo and slow once there are many resources, pages and widgets
A slow Filament panel on a server is most often running without the production caches.
3 causes, each with a fixBack end
Intervention Image will not save the file in a Laravel app
Can't write image data to path (/var/www/app/public/uploads/photo.jpg)
Intervention Image writes straight to a file path.
3 causes, each with a fixBack end
Laravel file upload returns 413 behind nginx
413 Content Too Large
A 413 means a limit refused the request body before Laravel could use it.
3 causes, each with a fixBack end
Laravel says the bootstrap/cache directory must be present and writable
The /var/www/app/bootstrap/cache directory must be present and writable.
Laravel writes its package manifest into bootstrap/cache and throws when that folder is missing or the current user cannot write to it.
2 causes, each with a fix