Results 1 to 5 of 5
  1. #1
    Join Date
    Jan 2009
    Posts
    46

    Unanswered: 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?

  2. #2
    Join Date
    Feb 2008
    Location
    Japan
    Posts
    3,483
    You already asked similar question in here.
    http://www.dbforums.com/db2/1647177-...-70-older.html

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

    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'

  3. #3
    Join Date
    Jul 2009
    Location
    NY
    Posts
    963
    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

  4. #4
    Join Date
    Jan 2009
    Posts
    46
    Quote Originally Posted by tonkuma
    You already asked similar question in here.
    http://www.dbforums.com/db2/1647177-...-70-older.html

    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!

  5. #5
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •