

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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)
- Related Questions & Answers
- How to get age from DOB in MySQL?
- Calculate age from date of birth in MySQL?
- Calculate Age from given Date of Birth in MySQL?
- How to calculate age in years from birthdate in MySQL?
- MySQL pagination without double-querying?
- Querying average row length in MySQL?
- Querying Data from Table using Node
- How to get an age from a D.O.B field in MySQL?
- Get maximum age from records with similar student names in MySQL
- Querying from part of object in an array with MongoDB
- Calculate age based on date of birth in MySQL?
- Querying null value in MongoDB?
- Finding average age from array of Objects using JavaScript
- Querying with MongoDB subelement?
- Can I get Age using BirthDate column in a MySQL query?
Advertisements