This time I had a problem in Mysql with message error :
2016-10-11 16:16:15
object(DateTime)#1 (3) { ["date"]=> string(26) "2016-10-11 16:16:15.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(12) "Asia/Jakarta" }
Catchable fatal error: Object of class DateTime could not be converted to string in /opt/lampp/htdocs/bus/index.php on line 16
I want the data to $d can get into mysql and the results of the timestamp can get into mysql without error.
And this is source code try:
$d = new DateTime('2016-10-11T09:16:15.000Z');$d->setTimezone(new DateTimeZone('Asia/Jakarta'));
echo $d->format('Y-m-d H:i:s')."<br />"; // 2016-10-06T09:50:54.000000
var_dump($d);
$host="localhost";
$user="root";
$pass="";
$db="baru";
/*Koneksi database*/
$spot = mysql_connect($host, $user, $pass) or die ("Koneksi gagal");
mysql_select_db($db, $spot) or die ("Koneksi gagal");
$sql = "INSERT INTO time (`timestamp`) values ( '$d' )";
mysql_query($sql);
with structure DB:
______ Name ________ Type _____________ Collation ______
1 id(Primary) int(40)
2 timestamp varchar(30) latin1_swedish_ci
Thanks.