php-mysqlHow to store a datetime value in a MySQL database using PHP?
Storing a datetime value in a MySQL database using PHP is a simple process. The following example code block can be used to store a datetime value in a MySQL database:
$date = date('Y-m-d H:i:s');
$sql = "INSERT INTO table_name (date_column) VALUES ('$date')";
The code above will insert the current date and time into the date_column
of the table_name
table.
The code consists of two parts:
$date = date('Y-m-d H:i:s');
- This line of code uses thedate()
function to get the current date and time in theY-m-d H:i:s
format.$sql = "INSERT INTO table_name (date_column) VALUES ('$date')";
- This line of code creates an SQL query to insert the$date
value into thedate_column
of thetable_name
table.
For more information, please refer to the following links:
More of Php Mysql
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to join tables with PHP and MySQL?
- How to get the version of MySQL using PHP?
- How to write an update query in MySQL using PHP?
- How to count the number of resulting rows in a MySQL database using PHP?
- How to use a MySQL union in PHP?
- How to set a timeout for MySQL query in PHP?
- How to create an SSL connection to MySQL using PHP?
- How to get the last insert ID in PHP MySQL?
- How to fetch data from MySQL in PHP?
See more codes...