How can we search a record from MySQL table having a date as a value in it?


It can be understood with the help of following example in which we are using the following data from the table named ‘detail_bday’ −

mysql> Select * from detail_bday;
+----+---------+------------+
| Sr | Name    | Birth_Date |
+----+---------+------------+
| 1  | Saurabh | 1990-05-12 |
| 2  | Raman   | 1993-06-11 |
| 3  | Gaurav  | 1984-01-17 |
| 4  | Rahul   | 1993-06-11 |
+----+---------+------------+
4 rows in set (0.00 sec)


Now, in the following two ways we can search records using the date −

mysql> Select * from detail_bday Where Birth_Date = '1993-06-11';
+----+-------+------------+
| Sr | Name  | Birth_Date |
+----+-------+------------+
| 2  | Raman | 1993-06-11 |
| 4  | Rahul | 1993-06-11 |
+----+-------+------------+
2 rows in set (0.00 sec)

mysql> Select * from detail_bday Where Date(Birth_Date) = '1993-06-11';
+----+-------+------------+
| Sr | Name  | Birth_Date |
+----+-------+------------+
| 2  | Raman | 1993-06-11 |
| 4  | Rahul | 1993-06-11 |
+----+-------+------------+
2 rows in set (0.00 sec)

Updated on: 30-Jan-2020

61 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements