- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
How can we find the employees from MySQL table whose age is greater than say 30 years, providing the only date of birth on the table?
To understand this concept, we are using the data from table ‘emp_tbl’ as follows −
mysql> Select * from emp_tbl; +--------+------------+ | Name | DOB | +--------+------------+ | Gaurav | 1984-01-17 | | Gaurav | 1990-01-17 | | Rahul | 1980-05-22 | | Gurdas | 1981-05-25 | | Naveen | 1991-04-25 | | Sohan | 1987-12-26 | +--------+------------+ 6 rows in set (0.00 sec) mysql> SELECT Name,SYSDATE(),DOB,DATEDIFF(SYSDATE(),DOB)/365 AS AGE from emp_tbl WHERE(DATEDIFF(SYSDATE(), DOB)/365)>30; +--------+---------------------+------------+---------+ | Name | SYSDATE() | DOB | AGE | +--------+---------------------+------------+---------+ | Gaurav | 2017-12-26 22:33:24 | 1984-01-17 | 33.9644 | | Rahul | 2017-12-26 22:33:24 | 1980-05-22 | 37.6219 | | Gurdas | 2017-12-26 22:33:24 | 1981-05-25 | 36.6137 | | Sohan | 2017-12-26 22:33:24 | 1987-12-26 | 30.0219 | +--------+---------------------+------------+---------+ 4 rows in set (0.10 sec)
- Related Articles
- Calculate age from date of birth in MySQL?
- Calculate age based on date of birth in MySQL?
- Calculate Age from given Date of Birth in MySQL?
- How can we import only specific columns from the text file, into MySQL table?
- How to find the age when date of birth is known? Using Java?
- How can I find the percentage of my users whose birth date is between 1980 and 1996 in MySQL?
- How can we create a table from an existing MySQL table in the database?
- How can we select records from a table if the absolute value of the difference between two values is greater than a certain number?
- How can we apply BIT_LENGTH() function on the column/s of MySQL table?
- How can we find the most recent and most oldest date from a table with the help of MySQL MAX() and MIN() functions?
- Find the difference between current date and the date records from a MySQL table
- How can we change the name of a MySQL table?
- How can we fetch all the records from a particular MySQL table?
- How can we add day/s in the date stored in a column of MySQL table?
- How can we update the values in one MySQL table by using the values of another MySQL table?

Advertisements