
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we insert current date automatically in a column of MySQL table?
With the help of CURDATE() and NOW() function, we can insert current date automatically in a column of MySQL table.
Example
Suppose we want to insert current date automatically in an OrderDate column of table year_testing the following query will do this −
mysql> Insert into year_testing (OrderDate) Values(CURDATE()); Query OK, 1 row affected (0.11 sec) mysql> Select * from year_testing; +------------+ | OrderDate | +------------+ | 2017-10-28 | +------------+ 1 row in set (0.00 sec) mysql> Insert into year_testing (OrderDate) Values(NOW()); Query OK, 1 row affected, 1 warning (0.12 sec) mysql> Select * from year_testing; +------------+ | OrderDate | +------------+ | 2017-10-28 | | 2017-10-28 | +------------+ 2 rows in set (0.00 sec)
- Related Articles
- How can we insert current year automatically in a YEAR type column of MySQL table?
- How can we insert current date and time automatically on inserting values in other columns in MySQL?
- How can we add a time interval to date stored in a column of MySQL table?
- How can we insert data into a MySQL table?
- How can we use INSERT() function to insert a new string into the value of a column of MySQL table?
- How can we add day/s in the date stored in a column of MySQL table?
- MySQL - Insert current date/time?
- How to insert current date/time in MySQL?
- How can we insert a new row into a MySQL table?
- How can we remove a column from MySQL table?
- How can we modify column/s of MySQL table?
- How can we put comments in a column of existing MySQL table?
- Insert current date in datetime format MySQL?
- How can we automatically define the structure of MySQL table same as the structure of another table?
- Can we insert records in a MySQL table without auto_increment values?

Advertisements