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 get the version of MySQL using PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to create an SSL connection to MySQL using PHP?
- How to change database in MySQL with PHP?
- How to update to null value in MySQL using PHP?
- How to generate a UUID in MySQL using PHP?
- What port to connect to MySQL from PHP?
- How to use a MySQL union in PHP?
- How to keep a connection open in PHP and MySQL?
- How to use a variable in a MySQL query using PHP?
See more codes...