Is there a way to set the time zone in the laravel 4 database.php configuration file?

Is there a way to set the time zone in the laravel 4 database.php configuration file (e.g. 'timezone' => 'UTC' )? I use mysql date, now other functions that give me two separate times for production and development.

thanks

+6
source share
4 answers

Go to app-> config-> app.php in your laravel directory. On line 43, you can change the default time zone to whatever you need.

Laravel 4 by default:

 'timezone' => 'UTC', 

Your time zone:

 'timezone' => 'America/Los_Angeles', 

This change is applied to the database migration. In addition, if you need to set different time intervals based on your environment settings, just add the directory to the app-> config directory corresponding to the name of the environment you specified (ie - "production"). Place the duplicate "app.php" in your newly created directory and change the time zone setting on line 43 accordingly.

+17
source

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

 date_default_timezone_set('UTC'); 

If you want to New York:

 date_default_timezone_set('America/New_york'); 

And so on. I tested it and worked great for me.

+2
source

Add 'timezone' => '+05: 30' inside 'mysql' in config-> database.php

 'mysql' => [ 'driver' => 'mysql', ..... ..... ..... 'timezone' => '+05:30' ], 
0
source

None of the answers available to me helped me, so I came up with this solution:

 'mysql' => array( ... 'options' => [ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET time_zone = "+00:00"', ], ), 

'options' should be added to mysql connection data (app / config / database.php).

0
source

Source: https://habr.com/ru/post/948805/


All Articles