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 > Date Difference

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-09-06, 11:17
vijay253 vijay253 is offline
Registered User
 
Join Date: Jan 2006
Posts: 7
Smile 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
Reply With Quote
  #2 (permalink)  
Old 01-09-06, 11:41
przytula przytula is offline
Registered User
 
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
Reply With Quote
  #3 (permalink)  
Old 01-09-06, 11:52
vijay253 vijay253 is offline
Registered User
 
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...
Reply With Quote
  #4 (permalink)  
Old 01-09-06, 13:02
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,534
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.
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