Reputation: 281
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
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
Reputation: 538
<?php
date_default_timezone_set("Europe/London");
?>
for mysql setting timezone like that-
SET time_zone = timezonename;
Upvotes: 0
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
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