Click here to Skip to main content
12,405,088 members (67,211 online)
Rate this:
Please Sign up or sign in to vote.
See more: SQL Oracle
I want to calculate current age of person from dob field in Oracle table.

Data type of DOB field is varchar and date stored in format 'DD-MON-YY'.

when I calculate current age of from date like 10-JAN-49 then query result age in negative.
and I observed that if date has year 13 to 49 it gives negative result.


22-NOV-83 -valid result
09-FEB-58 --valid result
05-JUN-49 - Invalid result like -36

Query Executed for reference

select round(MONTHS_BETWEEN(sysdate,to_date(dob,'DD-MON-RR'))/12)||' Yrs' from birth

Please help me.
Posted 1-Jul-13 23:45pm
Sudhakar Shinde 2-Jul-13 7:20am
I tried below query which works well..

That means something is wrong with the data in your birth table. Please check the data for dob column is correct. If possible you can share it in your question.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

That's caused by your defective design! How often can you read on CP and other programming sites that a date MUST NOT be stored as a char/varchar/nvarchar?
Looks like 05-JUN-49 gets interpreted as 05-JUN-2049, and consequently -36 is correctly calculated.
Change your design! That is the only correct solution!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 2 Jul 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100