Let us first create a table −
mysql> create table DemoTable(GetSundayDate date); Query OK, 0 rows affected (0.44 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2019-08-07'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('2018-09-05'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable values('2019-09-12'); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+---------------+ | GetSundayDate | +---------------+ | 2019-08-07 | | 2018-09-05 | | 2019-09-12 | +---------------+ 3 rows in set (0.00 sec)
Following is the query to get this coming Sunday's date for all the dates in the column −
mysql> SELECT date(GetSundayDate + INTERVAL 6 - weekday(GetSundayDate) DAY) AS ComingSundayDate from DemoTable;
This will produce the following output −
+------------------+ | ComingSundayDate | +------------------+ | 2019-08-11 | | 2018-09-09 | | 2019-09-15 | +------------------+ 3 rows in set (0.00 sec)