How to select a query for a selected day(2010-11-04) to current date using MySQL?


Let us first create a table −

mysql> create table DemoTable
(
   Joiningdate date
);
Query OK, 0 rows affected (0.56 sec)

Insert some records in the table using insert command −

mysql> insert into DemoTable values('2010-01-01');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable values('2010-03-31');
Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable values('2010-11-04');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable values('2012-12-31');
Query OK, 1 row affected (0.10 sec)
mysql> insert into DemoTable values('2019-01-03');
Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable values('2016-04-05');
Query OK, 1 row affected (0.11 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable;

This will produce the following output −

+-------------+
| Joiningdate |
+-------------+
| 2010-01-01  |
| 2010-03-31  |
| 2010-11-04  |
| 2012-12-31  |
| 2019-01-03  |
| 2016-04-05  |
+-------------+
6 rows in set (0.00 sec)

Following is the query for a selected date (2010-11-04) to current date using MySQL −

mysql> select *from DemoTable where Joiningdate >='2010-11-04' order by Joiningdate;

This will produce the following output −

+-------------+
| Joiningdate |
+-------------+
| 2010-11-04  |
| 2012-12-31  |
| 2016-04-05  |
| 2019-01-03  |
+-------------+
4 rows in set (0.00 sec)

Updated on: 10-Oct-2019

47 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements