bob jomes
bob jomes

Reputation: 281

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?

Upvotes: 1

Views: 7405

Answers (4)

Tina Vall
Tina Vall

Reputation: 172

I place the following at the top of my script:

date_default_timezone_set('Europe/London');
$formatted_date = date('Y-m-d H:i:s');

Upvotes: 0

Sunil Singh
Sunil Singh

Reputation: 538

 <?php
date_default_timezone_set("Europe/London");

?> 

for mysql setting timezone like that-

SET time_zone = timezonename;

Upvotes: 0

The Codesee
The Codesee

Reputation: 3783

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();
?>

Upvotes: 1

nl-x
nl-x

Reputation: 11832

Timestamps are timezone independent. Please show your code however.

And make sure your db and php server are running on the same time. You can set the timezone in your php.ini

Upvotes: 0

Related Questions