×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Convert Date of Birth to Age, results a negative number

Convert Date of Birth to Age, results a negative number

Convert Date of Birth to Age, results a negative number

(OP)
Greetings,

I'm able to convert a birthdate to age and all is fine except for years in the early 1900s, 1912 - 1920 for instance.  I need to correct this, what do I need to add to the query string?

All help is greatly appreciated!

Thanks,
JustATheory

RE: Convert Date of Birth to Age, results a negative number

We're missing at least one important piece of information.
What is your current query string?
What RDBMS are you using.

RE: Convert Date of Birth to Age, results a negative number

(OP)
Sorry about that!

Oracle 11g


SELECT ID, DOB, floor((months_between(sysdate, DOB))/12) age FROM table
;

Sample  Results

ID    DOB            AGE
1    25-Aug-54    57
2    10-Feb-85    27
3    20-Sep-80    31
4    10-Aug-18    -7

Many Thanks!

JustATheory

RE: Convert Date of Birth to Age, results a negative number

Jarl is correct - this is an Oracle question.
But the short answer is you are using an RR date model for years.  In essence, Oracle is rounding off your century, and years below 50 (or is it 51?  I forget) are assumed to be in the current century. So 10-Aug-18 is considered to be 2018, not 1918.

Try this:

CODE

  
SELECT TO_CHAR(dob, 'DD-MON-YYYY') AS real_date FROM table;
and the results of your original query will be clear.

RE: Convert Date of Birth to Age, results a negative number

(OP)
Thanks to both Jarl and carp,  this works perfectly and I'll check out the oracle 11g forum.

JustATheory

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close