I have a shared hosting mySql instance which has it\'s system_time_zone set to Pacific Standard Time and it\'s time_zone variable set to System, hence effectively it\'s runn
<?php
date_default_timezone_set('UTC'); //define local time
$date=date('l jS \of F Y h:i:s A'); //type of time shown
$conn=mysql_connect("localhost","root","") or die('Could not connect!'); //your database connection here
$db_selected = mysql_select_db('databasename', $conn); //select db
$result=mysql_query("INSERT INTO table (date) VALUES ('$date')", $conn);
?>
Simply sent the time as VARCHAR into db hope it helps and sorry for syntax errors (if there are any).
For shared hosting, you have to ask support-guys to help you and change default time zone for you? I had similar problem with Arcor hosting-provider, called them and they fixed it. Before that, I found temporary solution in date_default_timezone_set()
from PHP code. Probably the best solution is to ask someone who has privilege to change that parameter.
In short, MySQL
actually stores 'datetime
' data type fields internally as UTC
.
However
, PhpMyAdmin
shows you the dates using the server default time, hence your confusion.
For example, try adding this line before your SQL statement in PhpMyAdmin
:
SET @@session.time_zone='+00:00';
SELECT * FROM MY_TABLE
See the MySQL
documentation for further details, or the answer in this post: How to correctly set mysql timezone
Cheers Matt