bob jomes bob jomes - 7 months ago 8
PHP Question

Set timezone as Europe/London

I'm using PHP to insert a query into a database.

I am using

timestamp
for each query, however currently it is returning a time which is 7 hours behind my timezone (Europe/London).

How do I set the timezone as Europe/London when I insert it into a MYSQL database?

Answer

Try the code below:

(I have written the code in PDO as you did not specify which extension you were using.)

<?php
  date_default_timezone_set('Europe/London');
  $time_stamp = date('Y-m-d H:i:s');
  $stmt = $con->prepare("INSERT INTO tablename (datetime) VALUES ('".$time_stamp."')");
  $stmt->execute();
?>
Comments