Results 1 to 4 of 4

Thread: Date Difference

  1. #1
    Join Date
    Jan 2006
    Posts
    7

    Smile Unanswered: Date Difference

    Hi all,

    I have a char field Birthdate(YYYYMMDD) and I have to find the age of the person by substracting from CURRENT DATE. Can you please advice?

    thanks

  2. #2
    Join Date
    Nov 2004
    Posts
    374

    date

    using the date(charfield) and current date and build in functions
    you can find the nbr of days between 2 dates
    if col1 char(8) and value would be YYYYMMDD
    db2admin:/cygdrive/c/workdir: db2 select "col1,date(substr(col1,1,4)||'-'||substr(col1,5,2)||'-'||s
    ubstr(col1,7,2)) - current date from tx"

    COL1 2
    -------- ----------
    20060107 -2,
    Best Regards, Guy Przytula
    DB2/ORA/SQL Services
    DB2 DBA & Advanced DBA Certified
    DB2 Dprop Certified
    http://users.skynet.be/przytula/dbss.html

  3. #3
    Join Date
    Jan 2006
    Posts
    7

    Date Difference

    Thanks,

    I tried
    Current date - date(substr(BRTH_DT_CD,5,2)||'/'||substr(BRTH_DT_CD,7,2)||'/'||substr(BRTH_DT_CD,1,4))

    getting the result in date.

    But I want it in years meaning 27.6yrs for example.

    thanks again...

  4. #4
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650
    An example :
    values((current date - '2004-01-01')) is 20008.
    values(year(current date - '2004-01-01')) is 2
    values(month(current date - '2004-01-01')) is 0
    values(day(current date - '2004-01-01')) is 8

    Use this to calculate how you want to

    HTH

    Sathyaram


    Quote Originally Posted by vijay253
    Thanks,

    I tried
    Current date - date(substr(BRTH_DT_CD,5,2)||'/'||substr(BRTH_DT_CD,7,2)||'/'||substr(BRTH_DT_CD,1,4))

    getting the result in date.

    But I want it in years meaning 27.6yrs for example.

    thanks again...
    Visit the new-look IDUG Website , register to gain access to the excellent content.

Posting Permissions

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