- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Querying age from DOB in MySQL?
Let us first create a table −
mysql> create table DemoTable611 (DOB date); Query OK, 0 rows affected (0.99 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable611 values('1996-04-21'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable611 values('2001-01-31'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable611 values('2004-12-21'); Query OK, 1 row affected (0.22 sec) mysql> insert into DemoTable611 values('2000-02-03'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable611;
This will produce the following output −
+------------+ | DOB | +------------+ | 1996-04-21 | | 2001-01-31 | | 2004-12-21 | | 2000-02-03 | +------------+ 4 rows in set (0.00 sec)
Querying age from DOB −
mysql> select *from DemoTable611 where DOB >= (CURDATE() - INTERVAL 16 YEAR);
This will produce the following output −
+------------+ | DOB | +------------+ | 2004-12-21 | +------------+ 1 row in set (0.00 sec)
Advertisements