?
Solved

Need to calculate age in PLSQL using sysdate

Posted on 2003-11-30
4
Medium Priority
?
2,970 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 15

Accepted Solution

by:
andrewst earned 200 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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

719 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