If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > How Do I Calculate a Person's Age?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-11-09, 10:19
rockdave35 rockdave35 is offline
Registered User
 
Join Date: Jan 2009
Posts: 43
How Do I Calculate a Person's Age?

Hey guys,

I am stuck on this one. I need to run a query that will report a person's current age. I have a field in the database called MBR_BIRTH_DT which stores their birth date. So I wrote this:

YEAR(CURRENT DATE) - YEAR(B.MBR_BIRTH_DT) AS AGE

Then it occured to me that the query has to be more specific. A person with a birthdate occuring after Sept 11 would not be accurate in the query. Any suggestions?
Reply With Quote
  #2 (permalink)  
Old 09-11-09, 10:52
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
You already asked similar question in here.
How to Query for People Age 70 or Older?

And, Lenny answerd your question(How to calculate a person's AGE) in the thread, like:
Quote:
So, just make the right change and you'll the right query:

Quote:
SELECT A.MBR_SSN_NBR AS SSN,
A.MBR_F_NM AS FIRST_NAME,
A.MBR_L_NM AS LAST_NAME,
CHAR(A.MBR_BIRTH_DT, USA) AS BIRTH_DATE,
YEAR(A.MBR_BIRTH_DT) AS BIRTH_YEAR,
YEAR(CURRENT DATE - date(A.MBR_BIRTH_DT)) as AGE

FROM DSNP.PR01_T_MBR A,
DSNP.PR01_T_MBR_SYS B
where A.MBR_SSN_NBR = B.MBR_SSN_NBR
YEAR(CURRENT DATE - date(A.MBR_BIRTH_DT)) >= 70
and A.MBR_BIRTH_DT > date('0001-01-01')
and B.mbr_stat_cd = '1'
Reply With Quote
  #3 (permalink)  
Old 09-11-09, 11:08
Lenny77 Lenny77 is offline
Registered User
 
Join Date: Jul 2009
Location: NY
Posts: 886
Thank you tonkuma for your remembering.

What is interesting for me:

Everybody likes the topics with the simple questions, and almost nobody visits the topics with difficult problems.

Is this forum used as resort-spa for the programmers ?

Lenny
Reply With Quote
  #4 (permalink)  
Old 09-11-09, 12:07
rockdave35 rockdave35 is offline
Registered User
 
Join Date: Jan 2009
Posts: 43
Quote:
Originally Posted by tonkuma
You already asked similar question in here.
How to Query for People Age 70 or Older?

And, Lenny answerd your question(How to calculate a person's AGE) in the thread, like:

My bad, I should look before posting next time. Sorry!
Reply With Quote
  #5 (permalink)  
Old 09-11-09, 21:03
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by Lenny77
Thank you tonkuma for your remembering.

What is interesting for me:

Everybody likes the topics with the simple questions, and almost nobody visits the topics with difficult problems.

Is this forum used as resort-spa for the programmers ?

Lenny
This forum is often used by students to do their homework assignments.

But "some" of the difficult mathematical "problems" you like to discuss are things that rarely (if ever) occur in the world of a real DBA. They may exist for programmers, but are rarely attempted with SQL language.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On