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 use a MySQL union in PHP?
- How to write an update query in MySQL using PHP?
- How to export data from MySQL to Excel using PHP?
- How to set a timeout for MySQL query in PHP?
- How to update to null value in MySQL using PHP?
- How to return multiple rows as an array in MySQL using PHP?
- How to join tables with PHP and MySQL?
- How to check the result of an insert in PHP and MySQL?
- How to check if a record exists in PHP and MySQL?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
See more codes...