Written by Sai Sandeep Thota on February 24, 2013 in How to > Programming > SQL

How to Calculate Age in SQL

GET ALERTS:

Get our Latest updates delivered to your mailbox!

This command is used to calculate Age of a Person. For example if you have a Date of Birth field in your Database and you would like to calculate Age of a Person from that field.

Date of Birth: 01-Jan-1993
Age: 20.

How to Calculate Age in SQL

The following code will be applicable to Oracle SQL.

sql> SELECT TRUNC((MONTHS_BETWEEN(SYSDATE, YOURDATEFIELD))/12) AS "Age" FROM Your_Table;

You can get a rounded output of Age by using the following Query:

sql> SELECT ROUND((MONTHS_BETWEEN((SYSDATE, YOURDATEFIELD))/12) AS "Age" FROM Your_Table;

If you have any better solutions for this, Let me know 🙂

{ 0 comments… add one now }

Leave a Comment

Previous post:

Next post: