

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Insert current date to the database in MySQL?
To insert current date to the database, you can use NOW(). Following is the syntax −
INSERT INTO yourTableName(yourDateColumnName) VALUES(NOW());
If your column has datatype date then NOW() function inserts only current date, not time and MySQL will give a warning. To remove the warning, you can use CURDATE().
Let us first create a table −
mysql> create table insertcurrentdate -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> currentDate date -> ); Query OK, 0 rows affected (1.09 sec)
Following is the query to insert some records in the table using insert command. We have used both NOW() and CURDATE() to display current date −
mysql> insert into insertcurrentdate(currentDate) values(NOW()); Query OK, 1 row affected, 1 warning (0.24 sec) mysql> insert into insertcurrentdate(currentDate) values(CURDATE()); Query OK, 1 row affected (0.18 sec)
Following is the query to display all records from the table using select statement −
mysql> select * from insertcurrentdate;
This will produce the following output −
+----+-------------+ | Id | currentDate | +----+-------------+ | 1 | 2019-04-05 | | 2 | 2019-04-05 | +----+-------------+ 2 rows in set (0.00 sec)
- Related Questions & Answers
- MySQL - Insert current date/time?
- How to insert current date/time in MySQL?
- Insert current date in datetime format MySQL?
- How to insert current date and time in a database using JDBC?
- MySQL query to insert current date plus specific time?
- How to insert current date/ time using now() in a field with MySQL?
- Insert current time minus 1 hour to already inserted date-time records in MYSQL
- The easiest way to insert date records in MySQL?
- How can we insert current date automatically in a column of MySQL table?
- MySQL query to get the current date records wherein one of the columns displays current date
- Select dates between current date and 3 months from the current date in MySQL?
- How to insert DECIMAL into MySQL database?
- MySQL DATE function to return the difference between current date and joining date
- Change the curdate() (current date) format in MySQL
- Display Timestamp before the current date in MySQL
Advertisements