|
Problem with timezones in PHP and MySQL? | ||||||
asked | 1932 views | 1 answers. | |||||||
I am working web designing in php and mysql linux server. The Date() function in php and MySQL NOW() are giving different time value. The difference between these two is approximately 2.30hrs. Anyone tell me what's error and solution for this problem. | |||||||
LinuxMySQLTimezonePHP | |||||||
| |||||||
1
| PHP and MySql have separate default timezone setting.
First set PHP timezone by edit php.ini. 1. Search php.ini. In localhost search in php5 folder. For VPS search in /etc folder. 2. Add in [date] section as date.timezone = 'timezone'. Example : date.timezone = Asia/Calcutta. If you're running shared host, its not possible to edit php.ini, so you need use php function like: date_default_timezone_set('Asia/Calcutta'); Set timezone in MySql. 1. Get the timezone value by using date() function. i.e. $tmz = date('P'); 2. Run query: SET time_zone= $tmz; Now PHP and MySql have same timezone value. | ||||||
| |||||||
Add comment |
Post Your Answer Here :
Add comment