- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to add current date to an existing MySQL table?
To update an existing table, use UPDATE. With that, to set the current date, use the CURDATE() method −
update yourTableName set yourCoumnName=CURDATE();
Let us first create a table −
mysql> create table DemoTable -> ( -> DueDate datetime -> ); Query OK, 0 rows affected (0.58 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-01-10') ; Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values('2019-03-31'); Query OK, 1 row affected (0.18 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-01-10 00:00:00 | | 2019-03-31 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
Following is the query to add current date to existing table −
mysql> update DemoTable set DueDate=CURDATE(); Query OK, 2 rows affected (0.13 sec) Rows matched: 2 Changed: 2 Warnings: 0
Let us check the table records once again −
mysql> select *from DemoTable;
Output
This will produce the following output −
+---------------------+ | DueDate | +---------------------+ | 2019-06-22 00:00:00 | | 2019-06-22 00:00:00 | +---------------------+ 2 rows in set (0.00 sec)
Advertisements