PHP and MySQL TimeZone Synchronization

Info.Tech, PHP, SQL: Structured Query Language, Web Development Add comments

We all know the PHP and MySQL holds different timezone… what if we want both PHP and MySQL sync together by adjusting your PHP code only…

Here’s the solution:


define('TIMEZONE', 'Australia/Brisbane');


$dt = new DateTime();

// get time offset
$offset = $dt->format("P"); 

// update mysql timezone
mysql_query("SET time_zone='$offset';");



Thanks to Craig Buckler…


Comments are closed.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in