mysql query in php now()wrong date, i need help to this script

176 views Asked by At

This is my code :

date_default_timezone_set('Europe/Rome');
$dt2=date("Y-m-d H:i:s");
$query = $connection->prepare("INSERT INTO `sessions` ( `user_id`, `session_key`, `session_address`, `session_useragent`, `session_expires`) VALUES ( ?, ?, ?, ?, DATE_ADD('$dt2',INTERVAL 1 HOUR) )");

Since now() gave me a 5 hour time zone back, I use $dt2 (contains timestamp value of Europe/rome). In DATE_ADD, the first parameter will be the $dt2 instead of now(). I need to retrieve the actual Italian time by doing this code, I have already set the time zone in Italy in php.ini and echo the $dt2 it works perfectly but it fails to pass in query.

What wrong on my code? The format of the date on the database is datetime.

0

There are 0 answers