Focal Point
[SOLVED] Age Calculations

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/234108224

April 19, 2010, 12:29 PM
Arif
[SOLVED] Age Calculations
I am trying to calculate age for dateof birthcloumn.
I have following code
DEFINE FILE STAGE_CHILD_POS
CURRENTDT/Y=&DATEYYMD;
Birthday/YYMD=HDATE(STAGE_CHILD_POS.STAGE_CHILD_POS.BIRTHDATE, 'YYMD');
AGE/D12.2=DATEDIF(Birthday, CURRENTDT, 'Y');
END

I am getting error message:
(FOC36355) INVALID TYPE OF ARGUMENT #2 FOR USER FUNCTION DATEDIF
What am I doing wrong?

Arif

This message has been edited. Last edited by: Kerry,


WebFOCUS 7.6.10
Windows
HTML
April 19, 2010, 01:07 PM
jimster06
The field, CURRENTDT, is just a number. DATEDIF is expecting a date-formatted item.

If you just want to subtract the birth year from the current year, extract the birth year and do it arintmetically.


jimster06
DevStu WF 7.6.11
W7
HTML, PDF, EXL2K
April 19, 2010, 05:13 PM
Darin Lee
If you're wanting to calculate age from a date of birth, you should be subtracting today's date and the date of birth. Just using today's year may or may not give you the correct age. It would depend on whether or not the birthday has already occurred in this year.


Regards,

Darin



In FOCUS since 1991
WF Server: 7.7.04 on Linux and Z/OS, ReportCaster, Self-Service, MRE, Java, Flex
Data: DB2/UDB, Adabas, SQL Server Output: HTML,PDF,EXL2K/07, PS, AHTML, Flex
WF Client: 77 on Linux w/Tomcat
April 20, 2010, 09:30 AM
jgelona
Change your code as follows:

DEFINE FILE STAGE_CHILD_POS
  CURRENTDT/YYMD=&YYMD;
  Birthday/YYMD=HDATE(STAGE_CHILD_POS.STAGE_CHILD_POS.BIRTHDATE, 'YYMD');
  AGE/D12.2=DATEDIF(Birthday, CURRENTDT, 'Y');
END



In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
April 20, 2010, 09:42 AM
fatboyjim
Hi,

Can you use the following to determine age?

DEFINE FILE SOMETABLE  
AGE/I3=BIRTHDATE/365.25;
END


Best Regards,

Jimmy Pang


DEV: WF 7.6.10
TEST: WF 7.6.10
PROD: WF 7.6.10
MRE: WF 7.6.4
OS/Platform: Windows
Dev Studio: WF 7.7
Output: HTML, EXCEL, PDF, GRAPH, LOTUS, CSV
April 20, 2010, 09:52 AM
Arif
quote:
DEFINE FILE STAGE_CHILD_POS
CURRENTDT/YYMD=&YYMD;
Birthday/YYMD=HDATE(STAGE_CHILD_POS.STAGE_CHILD_POS.BIRTHDATE, 'YYMD');
AGE/D12.2=DATEDIF(Birthday, CURRENTDT, 'Y');
END

I think it was very helpful. I used
DEFINE FILE STAGE_CHILD_POS
CURRENTDT/YYMD=&YYMD;
Birthday/YYMD=HDATE(STAGE_CHILD_POS.STAGE_CHILD_POS.BIRTHDATE, 'YYMD');
AGE/D12.2=DATEDIF(Birthday, CURRENTDT, 'Y');
END

and it works just fine.


WebFOCUS 7.6.10
Windows
HTML
April 21, 2010, 09:29 AM
jgelona
quote:
Can you use the following to determine age?

DEFINE FILE SOMETABLE
AGE/I3=BIRTHDATE/365.25;
END



Jimmy, you can do that if you want the wrong answer. What that calculation will give you is an estimate of the number of years since 1/1/1901. Smart dates (those with a format of YYMD or MDYY or DMYY, etc.) are stored internally as the number of days since 12/31/1900. -1 is 12/30/1900, 0 is 12/31/1900, 1 is 1/1/1901, 2 is 1/2/1901, etc. If Birthday is 7/13/2005, as an integer it is 38180, divide that by 365.25 you get 104.53... years.


In FOCUS since 1985. Prod WF 8.0.08 (z90/Suse Linux) DB (Oracle 11g), Self Serv, Report Caster, WebServer Intel/Linux.
April 21, 2010, 10:10 AM
fatboyjim
I see.

Thanks for your response to describe what it's actually doing in the calculation.

I better double check some old report as they may not be correct.

Thanks again.


DEV: WF 7.6.10
TEST: WF 7.6.10
PROD: WF 7.6.10
MRE: WF 7.6.4
OS/Platform: Windows
Dev Studio: WF 7.7
Output: HTML, EXCEL, PDF, GRAPH, LOTUS, CSV