Tutorialspoint

1 Answer
karthikeya Boyini

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;

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;

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

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.