
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- How to get age from DOB in MySQL?
- Querying average row length in MySQL?
- Calculate age from date of birth in MySQL?
- MySQL pagination without double-querying?
- Calculate Age from given Date of Birth in MySQL?
- How to calculate age in years from birthdate 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
- Querying null value in MongoDB?
- Calculate age based on date of birth in MySQL?
- How to Calculate Age in Excel from Birthday?
- Querying internal array size in MongoDB?
- Querying with MongoDB subelement?

Advertisements