In this quick guide, I’ll be showing you how you can store date and time values on mysql table using php.
First thing that you need to do is to declare your database information.
<?php $con=mysql_connect("localhost","root","1234"); //host, user, password mysql_select_db("onstor",$con); //database and the connection information ?>
Then set your time zone. You can find a list of time zones that is recognized by php in this link: http://php.net/manual/en/timezones.php
I am living in the Philippines so my time zone would be declared this way:
The most important part is the value of date that you’re going to store in the database.
That’s the date format that is recognized by mysql. You can modify it but it might store something like this, if you don’t get it right:
And finally, the query that will store the value into the database:
mysql_query("INSERT INTO reports(DATE) VALUES('$date')");
That’s a quick guide on storing date and time values on mysql database. Hope you learned something