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:sformat.$sql = "INSERT INTO table_name (date_column) VALUES ('$date')";- This line of code creates an SQL query to insert the$datevalue into thedate_columnof thetable_nametable.
For more information, please refer to the following links:
More of Php Mysql
- How to check the result of an insert in PHP and MySQL?
- How to list tables in PHP MySQL?
- How to get the last insert ID in PHP MySQL?
- How to output XML from MySQL using PHP?
- How to set a timeout for MySQL query in PHP?
- How to export data from MySQL to Excel using PHP?
- How to check if a record exists in PHP and MySQL?
- How to create an SSL connection to MySQL using PHP?
- How to get the version of MySQL using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
See more codes...