Solved

Need to calculate age in PLSQL using sysdate

Posted on 2003-11-30
4
2,872 Views
Last Modified: 2012-05-04
Hello,
i am currently creating a member function in PLSQL and need to calculate the age of a person using the sysdate function. how can that be done? i am not sure how to split the sysdate to use only the year....

thanx!!
0
Comment
Question by:ZakdaMan
4 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 50 total points
ID: 9846366
Use MONTHS_BETWEEN to get number of months, divide by 12 to get years and then use FLOOR to remove digits after the decimal point:

SELECT FLOOR( MONTHS_BETWEEN( SYSDATE, date_of_birth ) / 12 )

To answer your second question, TRUNC(SYSDATE,'YYYY') returns the date TO_DATE('01-JAN-2003') (assuming current year is 2003).
0
 
LVL 7

Expert Comment

by:grim_toaster
ID: 9848710
Here's a link to a question I raised last week relating to date calculation, with some examples in the question of how you can calculate ages (but read the question as not all of them work, and I'm, still waiting to see if someone can give me an answer as to why!

http://www.experts-exchange.com/Databases/Oracle/Q_20808927.html
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question