Update record on a specific date matching the current date in MySQL


Let us first create a table −

mysql> create table DemoTable1822
     (
     Amount int,
     DueDate date
     );
Query OK, 0 rows affected (0.00 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable1822 values(1000,'2019-10-11');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1822 values(500,'2019-11-30');
Query OK, 1 row affected (0.00 sec)
mysql> insert into DemoTable1822 values(700,'2018-11-30');
Query OK, 1 row affected (0.00 sec)

Display all records from the table using select statement −

mysql> select * from DemoTable1822;

This will produce the following output −

+--------+------------+
| Amount | DueDate    |
+--------+------------+
|   1000 | 2019-10-11 |
|    500 | 2019-11-30 |
|    700 | 2018-11-30 |
+--------+------------+
3 rows in set (0.00 sec)

Here is the query to update database record on a specific date −

mysql> update DemoTable1822 set Amount=5000 where DueDate=curdate();
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1 Warnings: 0

Let us check the table records once again −

mysql> select * from DemoTable1822;

This will produce the following output −

+--------+------------+
| Amount | DueDate    |
+--------+------------+
|   1000 | 2019-10-11 |
|   5000 | 2019-11-30 |
|    700 | 2018-11-30 |
+--------+------------+
3 rows in set (0.00 sec)

Updated on: 24-Dec-2019

479 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements