我们如何从 MySQL 表中搜索包含日期作为值的记录?

mysqlmysqli database更新于 2025/4/20 13:00:17

可以借助以下示例来理解,其中我们使用名为"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)


现在,我们可以通过以下两种方式使用日期搜索记录 −

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)

相关文章


有用资源