Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Calculation of Age From db2 Table in format MM/DD/YYYY

Posted on 2004-04-13
2
Medium Priority
?
7,037 Views
Last Modified: 2008-01-16
I need help in calculating an age from a db2 table.
The age from the table is in the format: MM/DD/YYYY.

Are there any db2 functions that could help me calculate this number?
I would need to get the current date and subtract the field in the database; but would I have to parse out the mm,dd, and yyyy fields?

For example, in testing a birth_date of 11/15/1809,
I tried db2 "select current date - date(birth_date) from tablename where birth_date = '11/15/1809'"
but this returns the date in a format of 1940428.
which is the number of years followed by the number of days, I think.

Is there an easier way to perform this calculation?

Thanks In Advance.
John  
0
Comment
Question by:jtrapat1
[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
2 Comments
 
LVL 4

Expert Comment

by:bondtrader
ID: 10815004
There are many ways to do this, but here is a simple way:

select  integer( floor( (current date - birth_date ) / 10000 )) from tablename


Hope this helps

0
 

Accepted Solution

by:
sixeyed earned 500 total points
ID: 10815153
Hi John,

you don't need to parse the dates, but you need to convert them to numbers of days before subtracting. E.g.:

select days(current_date) - days(date('12/31/1935'))...

- will give you the number of days in between.

If you want to convert the result to months/years etc, specify the precision you want in the operand:

select (days(current_date) - days(date('01/29/1978'))) / 365.00...

- will give you the number of years to 2 d.p.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Recursive SQL in UDB/LUW (you can use 'recursive' and 'SQL' in the same sentence) A growing number of database queries lend themselves to recursive solutions.  It's not always easy to spot when recursion is called for, especially for people una…
Recursive SQL in UDB/LUW (it really isn't that hard to do) Recursive SQL is most often used to convert columns to rows or rows to columns.  A previous article described the process of converting rows to columns.  This article will build off of th…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

704 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