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 get the error message for a MySQL query using PHP?
- How to use a variable in a MySQL query using PHP?
- How to get the version of MySQL using PHP?
- How to write an update query in MySQL using PHP?
- How to update to null value in MySQL using PHP?
- How to fetch data from MySQL in PHP?
- How to use utf8mb4_unicode_ci in MySQL with PHP?
- How to order by a column in ascending order in MySQL using PHP?
- How to get a single value from query in PHP MySQL?
- How to escape a string for MySQL in PHP?
See more codes...