Method to insert date in MySQL: First open the script file; then insert the date through the [INSERT INTO tablename (col_name, col_date) VALUE ('DATE: Auto CURDATE()',CURDATE())] command.
#To create a dynamic modern website, a database must be used, and MySQL can be said to be the preferred database platform. Specifying the date of input is critical to the structure and timing of articles, posts, and replies in dynamic websites.
MySQL provides several data types for storing dates in its database system: DATE, TIMESTAMP, DATETIME, and YEAR.
How to use the DATE statement
The default way to store dates in a MySQL database is to use DATE. The correct format of DATE is: YYYY-MM-DD. If you try to enter a date in a format other than year-month-day, it may work but not store the date as expected.
In order to run the MySQL Insert command and add the current date to the table, you can use MySQL's built-in function CURDATE() in the query.
Example of inserting date in MySQL using CURDATE
$query_auto = "INSERT INTO tablename (col_name, col_date) VALUE ('DATE: Auto CURDATE()', CURDATE() )";
Also, you can run the query to set the date manually
How to set the date in MySQL Example of manually inserting dates in
$query_manual = "INSERT INTO tablename (col_name, col_date) VALUES ('DATE: Manual Date', '2019-7-04')";
All of these queries can be made by using the command line, scripts (written in PHP, Perl, Python, etc.) or by inserting in NTC Hosting’s sophisticated web hosting control panel PHPMyAdmin interface to run.
Additionally, there is a declaration that allows you to set only the year of the event. The Year statement uses the YYYY format, ranging from 1901 to 2155 (for years outside this range, you need to use the DATE statement)
Related mysql video tutorial recommendations: "mysql tutorial"
This article is about the method of inserting dates in MySQL. I hope it will be helpful to friends in need!
The above is the detailed content of How to insert date in MySQL?. For more information, please follow other related articles on the PHP Chinese website!