Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way I can set timezone in laravel 4 database.php configuration file?

Is there any way I can set timezone in laravel 4 database.php configuration file (like 'timezone' => 'UTC')? I'm using mysql date, now and other functions which is giving me two separate time for production and development.

Thanks

like image 480
Mohammad Shoriful Islam Ronju Avatar asked Jul 05 '13 16:07

Mohammad Shoriful Islam Ronju


People also ask

How do I change the default timezone in php?

The date_default_timezone_set() function sets the default timezone used by all date/time functions in the script.

Where is date timezone in php INI?

1) Go to your phpinfo() page and search for Loaded Configuration File and open the php. ini file mentioned under that section. 2) Change the default timezone settings by adding your new timezone by modifying this line: date. timezone=Asia/Kolkata .


2 Answers

Go to app->config->app.php in your laravel directory. On line 43 you can alter the default timezone to whatever you need.

Laravel 4 default:

'timezone' => 'UTC',

Your timezone:

'timezone' => 'America/Los_Angeles',

This change will then carry over to your database migrations. Also, if you need to set different timezones based on environment settings, simply add a directory in app->config directory that corresponds to the environment name you specified (ie - "production"). Place a duplicate of "app.php" into your newly created directory and alter the timezone setting on line 43 accordingly.

like image 112
Chris J Avatar answered Oct 09 '22 20:10

Chris J


Yes, you can add the following at the top of database.php, before return array:

date_default_timezone_set('UTC');

If you want to New York:

date_default_timezone_set('America/New_york');

And so on. I have tested it and works fine to me.

like image 38
user2094178 Avatar answered Oct 09 '22 20:10

user2094178